I have a Customer table in which I store how much money is spent by each customer on each product. (Like in the first table given in the attached image)
What I want is to find how much money is spend for bundle product like in the second table.
This just a sample query I wrote for example
select EmailAddress
, case when Books>0 and Movies>0 then sum(Books + Movies) end as Books_Movies
, case when Books>0 and Games>0 then sum(Books + Games) end as Books_Games
, case when Movies>0 and Games>0 then sum(Movies + Games) end as Books_Music
from Customers
Any help is really appreciated
you are complicating your solution while it is as simple as this:
select EmailAddress
, (Books + Movies) as Books_Movies
, (Books + Games) as Books_Games
, (Movies + Games) as Books_Music
from Customers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.