查询主题下的二级回复和三级回复列表
SELECT
a.topic_id,count(*) numFROM
diz_reply AS a where a.parent_id<>'0' GROUP BY a.topic_id
查询一个班的男生数和女生数:
SELECT grade, COUNT (CASE WHEN sex = 1 THEN 1 /*sex 1为男生,2位女生*/
ELSE NULL
END) 男生数,
COUNT (CASE WHEN sex = 2 THEN 1
ELSE NULL
END) 女生数
FROM students GROUP BY grade;