Skip to content
Advertisement

While display group of table value in mysql it shows each and every value as ‘0’

my table

and it’s values are

Now, i am going to grouping table but returns value in 0 While group the table it returns each and every column value returns in 0. Why that is happened. I need present or absent instead of 0. Can anyone solve this logic error?

query also attached

Advertisement

Answer

sum(case when hour = 'P1' then status else 'null' end) p1

The problem is that you are suming numbers and litteral string 'null'.

You wanted null (without quotes) – or better yet, 0

Note that in MySQL evaluates true/false conditions as 1/0 in numeric context, which allows shortening the expression like:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement