declare @temp table (
id int identity(1,1),
deptname nvarchar(500),
type nvarchar(1),
value int
)
insert into @temp
select 'payroll','a',20
union all
select 'payroll','b',20
union all
select 'payroll','b',10
union all
select 'sales','a',20
union all
select 'sales','b',20
union all
select 'sales','b',10
select * from @temp
select deptname,a,b,c from
(select SUM(value) as value,deptname,type from @temp group by type,deptname) p
pivot (SUM(value) FOR type IN (a,b,c)) AS pvt
Thursday, October 4, 2012
simple example of pivot in sql
Subscribe to:
Post Comments (Atom)
ASP.NET Core
Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...
-
The error message you encountered ("DeleteService FAILED 1072: The specified service has been marked for deletion") indicates tha...
-
replace html of a div using jquery this is simple . just use .html() method of jquery to set new html for a div . $ ( "#divID&q...
-
declare @ProductIds nvarchar(50)='18,19' SELECT * FROM products Where (',' + @ProductIds +',' LIKE '%,' ...
No comments:
Post a Comment