業務情景一:
select
count(first_interview) first_interviews,
count(submit_time) submit_time,
count(length(concat(submit_time,bg_time))>26) submit_time,
count(followupdate) followupdate,
count(arrivaldate) arrivaldate,
count(*) reports
from dws.dws_awa_t_cal_recomperiods_result2
group by business_line,region,office,team,fullname
結果:
1 0 0 1 1 3
39 0 0 0 0 119
46 0 0 5 5 215
35 1 1 5 4 61
55 0 0 1 0 156
1 0 0 0 0 8
12 0 0 0 0 35
3 0 0 0 0 5
29 0 0 0 0 89
0 0 0 0 0 1
47 0 0 1 1 181
29 0 0 1 1 72
58 0 0 3 3 156
4 0 0 0 0 24
4 0 0 0 0 16
42 1 1 2 2 154
2 0 0 0 0 18
分析:為什麼count不同字段得出來的結果卻不同?
原因是coun計數的是檢索行中“非空”記錄數。
業務情景二:
是否可以同時count兩個字段,或者說我要同時判斷兩個字段是否有值,然後才count計數加上1,答案是可以的。
如上sql中有一句:
count(length(concat(submit_time,bg_time))>26) submit_time,
這句sql意思就是先連接配接兩個字段,并通過連接配接後的字段長度,來判斷是否兩個字段都有值,符合我們條件的才會count計數加上1。