select username,count(*) '´óÓÚ80' from t_user where score>=80 group by username
select username,count(*) '´óÓÚ90' from t_user where score>=90 group by username ËÖªµÀ½²ÕâÁ½¸öÓï¾äµÄ²éѯ½á¹ûºÏ²¢ÆðÀ´£¬²»ÊÇÓÃunion£¬¶øÊÇÈòéѯ½á¹û±ä³ÉÈýÁС£ÕâÈý ÁзֱðÊÇusername£¬´óÓÚ80£¬´óÓÚ90.SQL code: select username, sum(case when score>=90 then 1 else 0 end) , sum(case when score < 90 then 1 else 0 end) from t_user where score >= 80 group by username
SQL code: select username, sum(case when score>=90 then 1 else 0 end) as '´óÓÚ90', sum(case when score < 90 then 1 else 0 end) as '´óÓÚ80СÓÚ90' from tb where score>=80 group by username
SQL code: select username, sum(case when score>=80 then 1 end) as '´óÓÚ80' , sum(case when score >= 90 then 1 end) as '´óÓÚ90' from t_user where score >= 80 group by username