我有几个表想要创建具有多个日期范围列的查询。这是一个例子:
| 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 |
上面的两个查询可以返回两个不同的范围值,但我想在单个查询中获取范围值。
请帮忙。
提前致谢。
在
OR
子句中使用 WHERE
。
WHERE ((date BETWEEN '2011-01-01' AND '2011-01-30')
OR (date BETWEEN '2011-02-01' AND '2011-02-30'))
请帮忙提供以下资料