2011-06-06 129 views
0

我有幾個表,我想從哪裏創建含多個日期範圍列的查詢。這裏是一個例子:查詢中的多個日期範圍

  | Date Range_1 | Date Range_2 | 
      | 01-31 Jan | 01-30 Feb | 

      ---- col1,col2 -----col3, col4 ---- 



SELECT temp_a.* 
FROM (SELECT col_1,col_2, col_3 from xyz WHERE (date BETWEEN '2011-01-01' AND '2011-01-30') 
AND id = 70 
GROUP BY a1 a2) temp_a 
INNER JOIN table1 t1 ON a.id = t1.id 



SELECT temp_b.* 
FROM (SELECT col_1, col_2, col_3 from xyz WHERE (date BETWEEN '2011-02-01' AND '2011-02-30') 
AND id = 70 
GROUP BY a1 a2) temp_b 
INNER JOIN table1 t1 ON b.id = t1.id 

I need all the column from temp_a and temp_b like this 

|temp_a.col_1 | temp_a.col_2 | temp_a.col_3 | temp_b.col_1 | temp_b.col_2 | temp_b.col_3 | 

以上兩個查詢可以返回兩個不同的範圍值,但我想在單個查詢中獲取範圍值。

請幫忙。

在此先感謝。

  • Shahidul,孟加拉國達卡。

回答

2

WHERE子句中使用OR

WHERE ((date BETWEEN '2011-01-01' AND '2011-01-30') 
     OR (date BETWEEN '2011-02-01' AND '2011-02-30')) 
+0

我需要來自這兩個表的數據(我想加入查詢任何如何) – Shahidul 2011-06-06 10:49:19

+0

您已經有加入。只需將我的WHERE子句替換掉即可。 – 2011-06-06 11:00:59