1.一次性查询每个分类出现的次数
eg:查询每个班报名各种补习班的人数
select class_id,
count(case when class_type = 1 then '语文班' end) as 语文班,
count(case when class_type = 2 then '奥数班' end) as 奥数班,
count(case when class_type = 3 then '象棋班' end) as 象棋班,
count(case when class_type = 4 then '游泳班' end) as 游泳班,
count(case when class_type = 5 then '绘画班' end) as 绘画班
from mams_class_relation group by class_id;
2.查询字段内容为空(字符串空串,非null)的数据。
select * from table where column is null or trim(column)='';