How to return a default value when no rows are returned from the select statement

前端 未结 7 1782
庸人自扰
庸人自扰 2021-01-22 13:26

I have a select statement that returns two columns, a date column, and a count(value) column. When the count(value) column doesn\'t have any records,

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 13:56

    select convert(varchar(25), DateTime, 101) as recordDate,
           CASE WHEN count(value) =0 THEN 0 ELSE COUNT(value) END  recordCount
    from History
    where Value < 700
    group by convert(varchar(25), DateTime, 101)
    

提交回复
热议问题