亮點:一、結合使用length()及replace(str,',','')來實現其計數功能;.net
二、溫故而知新,sum, 對比count 和sumblog
三、嵌套查詢格式書寫漂亮,一方面便於養成Python書寫習慣,同時,便於排查錯誤。get
附代碼:it
select sum(case when num = 1 then 1 else 0 end) sum1,
sum(case when num = 2 then 1 else 0 end) sum2,
sum(case when num = 3 then 1 else 0 end) sum3,
sum(case when num = 4 then 1 else 0 end) sum4,
sum(case when num = 5 then 1 else 0 end) sum5,
sum(case when num >5 then 1 else 0 end) othertable
from(
select length(iterm)-length(replace(iterm,',',''))+1 as num
from database.table
) A
備註:iterm爲字段名select