Hello all,
I have data like :-
year amt
2004 10
2005 20
2006 30
Now i want output as:-
2004 2005 2006
10 30 60
but i have to use here group by on year.So, i need a single
query within that i can find.
Answer Posted / sagun sawant
select ((select sum((case when year = '2004' then (amt)
else 0 end)) from account )) as [2004]
,((select sum((case when year = '2005' then (amt)
else 0 end)) from account )) as [2005]
,((select sum((case when year = '2006' then (amt)
else 0 end)) from account )) as [2006]
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
Can you pass expressions to function parameters?
Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?
How many partitions a clustered index has by default in sql server 2012?
What are group functions in query statements in ms sql server?
Indexes are updated automatically is the full-text index also updated automatically?
What is 1nf normalization form?
Where actually sql azure database is hosted?
How to make a remote connection in a database?
List out some of the requirements to set up a sql server failover cluster?
What is the difference between a function and a stored procedure?
How to create an identity column?
How to apply filtering criteria at group level with the having clause in ms sql server?
Please explain go command in sql server?
What is the rdl file?
Explain sub-query?