mysql相關

mysql
1.union

select name  from tb1 where score=(
SELECT max(score) from tb1 

)
union 
select name  from  tb1 where score=(
SELECT min(score) from tb1 

)

2.兩門分數加起來的第2-5名,group by

select name, count(score),sum(score)  from tb1 
 group by name 
HAVING count(score)=2 
ORDER BY
sum(score) desc 
limit 1,4;

3.兩門加起來低於 150,having分組過濾條件

select name ,sum(score) from tb1  group by name 
having count(score)=2 
and   sum(score)<150

4.兩門平均分在60-80,having分組過濾條件+avg()平均

select name ,avg(score) from tb1  group by name 
having count(score)=2 
and  avg(score)>=60 and  avg(score)<=80;

5.總分大於150,平均分小於90的人數
#總分大於150,平均分小於90的人數

select count(*)as '符合人數'
from
(select id from  tb1
group by name
HAVING sum(score)>100 and avg(score)<90

) a

6.看不懂,語文不好…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章