###### 现有‘tables’表,字段如下: ###### 姓名、科目、全部题目、正确题目 #### 1、现要一条sql查询出每个人的统计,包括全部数量和正确数量,并排序。 SELECT count(*) as all_num, sum(if(right_flg="Y",1,0)) as right_num, name FROM tables GROUP BY name ORDER BY right_num DESC, all_num DESC 2、查询出正确数大于50的人 SELECT * FROM tables group by name HAVING count(right_num)>=50 ;