0

Please help me with this. I have the data as this:

ID          Name          TotalCost     
----   ----------------  ----------  
1      Wash, Dry & Fold     175.00    
2      Hand Wash and Fold   275.00
3      Pressing Only        25.00   
4     Hand Wash and Fold    205.00
5     Dry Clean             395.00
6     Pressing Only         100.00

I would like to display my table like this: Is this possible using PIVOT without Agrregate?

ID     Wash, Dry & Fold    Hand Wash and Fold  Pressing Only    Dry Clean 
----   ----------------   -----------------    --------------   -----------
1         175.00    
2                              275.00
3                                                                25.00   
4                              205.00
5                                                               395.00
6                                                 100.00

Thank you.

Glyieh
  • 41
  • 1
  • 11
  • You will still use an aggregate function, it's required for pivot - you'll need to use `sum()`. Have you tried to write the query to get the result? – Taryn Sep 15 '16 at 13:30
  • @bluefeet I tried, It sum each column. I need to display the table like the example above. Is there anything way to display like that? – Glyieh Sep 16 '16 at 05:17
  • Please change your title...SUM is an Aggregate – Prisoner ZERO May 24 '18 at 13:43

1 Answers1

0
select *
from 
(
  select ID, Name, TotalCost
  from Table
) src
pivot
(
  sum(TotalCost)
  for Name in ('Wash, Dry & Fold','Hand Wash and Fold','Pressing Only','Dry Clean' )
) piv;
Webdev
  • 617
  • 6
  • 24