Sum while transposing

Database
Tourist

Sum while transposing

I have a data like this

Name      date                        brand               Count
A           Mon, Jan 01, 2018     AA                       3
A           Mon, Jan 01, 2018     BB                      1
B           Mon, Jan 01, 2018    CC                        0
B           Mon, Jan 01, 2018    AA                        1
A           Mon, Jan 01, 2018    AA                         2
A           Mon, Jan 01, 2018    BB                         3
B          Mon, Jan 01, 2018     CC                        5

 

and need an ouput like this

 

NamedateAABBCC
AMon, Jan 01, 2018540
BMon, Jan 01, 2018705



1 REPLY
Highlighted
Junior Contributor

Re: Sum while transposing

Can you show your existing SQL?

 

You probably need to remove the brand from GROUP BY and move it into CASE like this

 

SUM(CASE WHEN brand = 'AA' THEN 1 ELSE 0 END) AS AA

Of couse this is only possible when the brands are know in advance.

 

In TD16 there's a new PIVOT syntax to get the same...