最長的SQL語句

2021-08-29 17:29:56 字數 4631 閱讀 6883

今天無意之中,我竟然寫出我目前寫得最長的一條sql語句:

select m.stu_name stuname,

(select sourenumber from studentsoure where subjectid='1' and stu_id='20081030001' and classid='18') '期中英語',

(select sourenumber from studentsoure where subjectid='2' and stu_id='20081030001' and classid='18') '期中語文',

(select sourenumber from studentsoure where subjectid='3' and stu_id='20081030001' and classid='18') '期中數學',

(select sourenumber from studentsoure where subjectid='4' and stu_id='20081030001' and classid='18') '期中政治',

(select sourenumber from studentsoure where subjectid='5' and stu_id='20081030001' and classid='18') '期中歷史',

(select sourenumber from studentsoure where subjectid='6' and stu_id='20081030001' and classid='18') '期中地理',

(select sourenumber from studentsoure where subjectid='7' and stu_id='20081030001' and classid='18') '期中生物',

(select sourenumber from studentsoure where subjectid='8' and stu_id='20081030001' and classid='18') '期中化學',

(select sourenumber from studentsoure where subjectid='9' and stu_id='20081030001' and classid='18') '期中物理',

(select sourenumber from studentsoure where subjectid='10' and stu_id='20081030001' and classid='18') '期中體育',

(select sourenumber from studentsoure where subjectid='11' and stu_id='20081030001' and classid='18') '期中班級排名',

(select sourenumber from studentsoure where subjectid='12' and stu_id='20081030001' and classid='18') '期中年級排名',

(select sourenumber from studentsoure where subjectid='13' and stu_id='20081030001' and classid='18') '期末英語',

(select sourenumber from studentsoure where subjectid='14' and stu_id='20081030001' and classid='18') '期末語文',

(select sourenumber from studentsoure where subjectid='15' and stu_id='20081030001' and classid='18') '期末數學',

(select sourenumber from studentsoure where subjectid='16' and stu_id='20081030001' and classid='18') '期末政治',

(select sourenumber from studentsoure where subjectid='17' and stu_id='20081030001' and classid='18') '期末歷史',

(select sourenumber from studentsoure where subjectid='18' and stu_id='20081030001' and classid='18') '期末地理',

(select sourenumber from studentsoure where subjectid='19' and stu_id='20081030001' and classid='18') '期末生物',

(select sourenumber from studentsoure where subjectid='20' and stu_id='20081030001' and classid='18') '期末化學',

(select sourenumber from studentsoure where subjectid='21' and stu_id='20081030001' and classid='18') '期末物理',

(select sourenumber from studentsoure where subjectid='22' and stu_id='20081030001' and classid='18') '期末體育',

(select sourenumber from studentsoure where subjectid='23' and stu_id='20081030001' and classid='18') '期末班級排名',

(select sourenumber from studentsoure where subjectid='24' and stu_id='20081030001' and classid='18') '期末年級排名',

(select sourenumber from studentsoure where subjectid='25' and stu_id='20081030001' and classid='18') '同桌',

(select sourenumber from studentsoure where subjectid='26' and stu_id='20081030001' and classid='18') '組長',

(select sourenumber from studentsoure where subjectid='27' and stu_id='20081030001' and classid='18') '班長',

(select sourenumber from studentsoure where subjectid='28' and stu_id='20081030001' and classid='18') '語文課代表',

(select sourenumber from studentsoure where subjectid='29' and stu_id='20081030001' and classid='18') '英語課代表',

(select sourenumber from studentsoure where subjectid='30' and stu_id='20081030001' and classid='18') '數學課代表',

(select sourenumber from studentsoure where subjectid='31' and stu_id='20081030001' and classid='18') '儀容儀表情況',

(select sourenumber from studentsoure where subjectid='32' and stu_id='20081030001' and classid='18') '作業繳納情況',

(select sourenumber from studentsoure where subjectid='33' and stu_id='20081030001' and classid='18') '值日衛生情況',

(select sourenumber from studentsoure where subjectid='34' and stu_id='20081030001' and classid='18') '考勤情況(含早操)',

(select sourenumber from studentsoure where subjectid='35' and stu_id='20081030001' and classid='18') '午休檢查情況',

(select sourenumber from studentsoure where subjectid='36' and stu_id='20081030001' and classid='18') '何時何地受獎勵(處分)',

(select sourenumber from studentsoure where subjectid='37' and stu_id='20081030001' and classid='18') '班主任談話情況(與家長)'

from studentsoure o inner join studentma m on o.stu_id=m.stu_id

where m.stu_id='20081030001' and m.classid='18' group by m.stu_name

這是我幫同學寫的一條sql,由於所有資料都儲存在一張表裡,但列印時又一列列印出來。

真是累死我了!

接入號最長匹配的兩種sql語句

接入號最長匹配的兩種sql語句,好像速度都一樣,查出來的結果可能不一樣,都能滿足接入號最長匹配的要求 都是oracle的語法。方法一 select max length t.oldaccessno as accessnolength,max t.newaccessno as newaccessno,...

SQL 語句的TOP,Distinct語句

select top 3 from dbo.mystudent 查詢student表中前3條所有的資料 select top 3 s name,s gender,s address,s age from dbo.mystudent 查詢student表中前3條部分的資料 select top 3 p...

SQL語句 limit 語句

select from table limit offset,rows rows offset offset 在我們使用查詢語句的時候,經常要返回前幾條或者中間某幾行資料,這個時候怎麼辦呢?不用擔心,mysql 已經為我們提供了上面這樣乙個功能。limit 子句可以被用於強制 select 語句返回...