Mysql面試題


1.用一條SQL 語句 查詢出每門課都大於80 分的學生姓名

name   kecheng   fenshu
張三    語文       81
張三     數學       75
李四     語文       76
李四     數學       90
王五     語文       81
王五     數學       100
王五     英語       90

select distinct name from table where name not in (select distinct name from table where fenshu<=80)
select name from table group by name having min(fenshu)>80

2、學生表 如下:
自動編號   學號   姓名 課程編號 課程名稱 分數
1        2005001 張三 0001     數學    69
2        2005002 李四 0001      數學    89
3        2005001 張三 0001      數學    69
刪除除了自動編號不同, 其他都相同的學生冗余信息

delete tablename where 自動編號 not in(select min( 自動編號) from tablename group by學號, 姓名, 課程編號, 課程名稱, 分數)

3、一個叫 team 的表,里面只有一個字段name, 一共有4 條紀錄,分別是a,b,c,d, 對應四個球對,現在四個球對進行比賽,用一條sql 語句顯示所有可能的比賽組合.
你先按你自己的想法做一下,看結果有我的這個簡單嗎?

select a.name, b.name
from team a, team b 
where a.name < b.name

4、.請用SQL 語句實現:從TestDB 數據表中查詢出所有月份的發生額都比101 科目相應月份的發生額高的科目。請注意:TestDB 中有很多科目,都有1 -12 月份的發生額。
AccID :科目代碼,Occmonth :發生額月份,DebitOccur :發生額。
數據庫名:JcyAudit ,數據集:Select * from TestDB

select a.*
from TestDB a 
,(select Occmonth,max(DebitOccur) Debit101ccur from TestDB where AccID='101' group by Occmonth) b
where a.Occmonth=b.Occmonth and a.DebitOccur>b.Debit101ccur

5、面試題:怎么把這樣一個表兒
year   month amount
1991   1     1.1
1991   2     1.2
1991   3     1.3
1991   4     1.4
1992   1     2.1
1992   2     2.2
1992   3     2.3
1992   4     2.4
查成這樣一個結果
year m1   m2   m3   m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4 

SELECT year,
(SELECT amount from aaa m where month = 1 and m.year = aaa.year) as m1,
(SELECT amount from aaa m where month = 2 and m.year = aaa.year) as m2,
(SELECT amount from aaa m where month = 3 and m.year = aaa.year) as m3,
(SELECT amount from aaa m where month = 4 and m.year = aaa.year) as m4
from aaa GROUP BY year

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM