SELECT SUM returns a row when there are no records

后端 未结 8 1041
囚心锁ツ
囚心锁ツ 2021-01-17 10:38

I\'m finding some problems with a query that returns the sum of a field from a table for all the records that meet certain conditions. I expected to receive a \"No records f

相关标签:
8条回答
  • 2021-01-17 11:14

    How about this:

    select my_sum
    from
    (SELECT SUM(dummy) as my_sum FROM DUAL WHERE 1=2)
    where
    my_sum is not null
    
    0 讨论(0)
  • 2021-01-17 11:16

    use the coalesce function of mysql and do:

    SELECT COALESCE(SUM(where),0) FROM table WHERE condition = variable
    
    0 讨论(0)
提交回复
热议问题