选择日期,numberOfXMoreThan20,numberOfXLessThan20,otherValues
来自表格
分组(日期,X> 20和X <20)
我的方式,但我认为这不好
选择less20.id_date,a,b
从 (选择id_date,count(Duree_Attente_Avant_Abandon)作为a cnav_reporting.contact_global,其中Duree_Attente_Avant_Abandon&gt; 20 group by id_date)为less20, (选择 id_date,计数(Duree_Attente_Avant_Abandon) 作为b来自 cnav_reporting.contact_global在哪里 Duree_Attente_Avant_Abandon&lt; 20 group by id_date)as more20,其中
less20.id_date = more20.id_date
感谢
答案 0 :(得分:4)
SELECT
date,
SUM( IF(X > 20), 1, 0 ) AS overTwenty,
SUM( IF(X < 20), 1, 0 ) AS belowTwenty,
otherValue
FROM `table`
GROUP BY `date`, `otherValue`
答案 1 :(得分:1)
您可能正在寻找COUNT
聚合:
SELECT COUNT(*) FROM table Where X > 20