sql函數(shù)count()中可以直接加條件
例:select
?? ?????????count(status = '1' or null) as "ok",
?? ?????????count(status = '2' or null) as "warning",
?? ?????????count(status in ('3', '4') or null) as "ng",
?? ?????????count(id) as "sum"
????????from
?? ?????????test
運(yùn)行結(jié)果:2?? ?4?? ?2?? ?8
由此可見,count()中追加條件是好用的
注意:條件后需追加"OR NULL",沒有的話count()中的條件失效。
至于為什么要加上這個(gè),鏈接如下文章來源:http://www.zghlxwxcb.cn/news/detail-702156.html
https://blog.csdn.net/qq_32719287/article/details/79513164:文章來源地址http://www.zghlxwxcb.cn/news/detail-702156.html
到了這里,關(guān)于sql中count()中加條件的用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!