想對查詢出來的結果集再次操作,就可以把查詢出來的結果集當成一個臨時表
對臨時表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 語句是不能放在內層查詢語句的,只能放在外面