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 语句是不能放在内层查询语句的,只能放在外面

 

posted @ 2021-04-27 16:37  乐天开门  阅读(1025)  评论(1)    收藏  举报