select username,count(*) '大于80' from t_user where score>=80 group by usernameselect username,count(*) '大于90' from t_user where score>=90 group by username
谁知道讲这两个语句的查询结果合并起来,不是用union,而是让查询结果变成三列。这三
列分别是username,大于80,大于90.
谁知道讲这两个语句的查询结果合并起来,不是用union,而是让查询结果变成三列。这三
列分别是username,大于80,大于90.
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
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
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
sum(case when score >= 80 then 1 else 0 end) [大于80],
sum(case when score >= 90 then 1 else 0 end) [大于90]
from t_user
group by usernameselect username,
sum(case when score > 80 then 1 else 0 end) [大于80],
sum(case when score > 90 then 1 else 0 end) [大于90]
from t_user
group by username