顯示具有 SQL 標籤的文章。 顯示所有文章
顯示具有 SQL 標籤的文章。 顯示所有文章

2010年7月30日 星期五

多表取不重複值

兩章表...找出範圍內的所有值..並且不重複
● union all 重複
● union 不重複

group by 是決定重不重複的關鍵。


select
*
from (
select
ProductName, Money
from
TABLE_A
where
Time between '2009-08-04' and '2010-05-07'

union all

select
ProductName, Money
from
TABLE_B
where
Time between '2009-08-04' and '2010-05-07'
) as tmp
group by ProductName, Money

2009年12月1日 星期二