【記錄一個問題】MariaDB 10.1.9 中with rollup的神器問題


我想統計每天數據的處理狀態的匯總,於是寫了這樣一條語句:

1 select * from (
2 select ifnull(date(update_time),'_30天匯總') as dtm, ifnull(b.status_name, '_當天匯總') as status_name,count(1) as cnt
3 from `t_workflow` a left outer join dict_status b on a.status=b.status 
4 where a.update_time>=DATE_SUB(CURRENT_DATE(), INTERVAL 3 DAY)
5 group by date(update_time),b.status_name with rollup 
6 ) a order by 1 desc, 2 ASC

神奇的事情發生了,當天匯總的數據居然出現了兩條:

最后發現是ifnull的問題,修改成如下后正確:

1 select * from (
2 select date(update_time) as dtm, b.status_name as status_name,count(1) as cnt
3 from `t_workflow` a left outer join dict_status b on a.status=b.status 
4 where a.update_time>=DATE_SUB(CURRENT_DATE(), INTERVAL 3 DAY)
5 group by date(update_time),b.status_name with rollup 
6 ) a order by 1 desc, 2 ASC

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com