MySQL Forums
Forum List  »  Newbie

Re: Select with If and With Rollup
Posted by: Lars Braake
Date: April 10, 2021 11:41PM

Hi,thanks for helping. I'm not able to add files or pics to that forum, so I will show you the example table:

Table Test
ID,Type,Value
1 ,1, 100
2 ,1, 200
3 ,2, 10
4 ,2, 20

Now I run this select
SELECT id, type, If(type = 1, SUM(value),0) AS Value FROM `test` GROUP BY type, id WITH ROLLUP

and get

ID Type Value What I expect
1 1 100. Correct
2 1 200. Correct
NULL 1 300. Correct - Sum of Value from ID 1 and 2
3 2 0. Correct
4 2 0. Correct
NULL 2 0. Correct - Sum of Value from ID 3 and 4
NULL NULL 0 ?? I expected 300 - Sum of all IDs.

Options: ReplyQuote


Subject
Written By
Posted
Re: Select with If and With Rollup
April 10, 2021 11:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.