select結果集的再次select


想對查詢出來的結果集再次操作,就可以把查詢出來的結果集當成一個臨時表

對臨時表t1操作

語法:select  sum(a), b from

( select a, b ,c

from table1

join table2 

on table1.a = table2.a 

where table1.a='1')  t

group by b 

 

復雜一點,對兩個臨時結果集t1,t2操作

select  sum(a), b from

( select a, b ,c

from table1

join table2 

on table1.a = table2.a 

where table1.a='1')  t1

join t2

( select a, b ,c

from table1

join table2 

on table1.a = table2.a 

where table1.a='1')  t2

on t1.a=t2.a

group by b 

order by b

需要注意一點的是order by 語句是不能放在內層查詢語句的,只能放在外面

 


免責聲明!

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



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