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