Multiple Date Range in a query
I have few tables from where i want to create a query with multiple date range column. Here is an example:
| 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 |
the above two query can return two different range value but i want to get the ranged values in a single query.
Please help.
thanks in advance.
- Shahidul, Dhaka, Bangladesh.
Use OR
in the WHERE
clause.
WHERE ((date BETWEEN '2011-01-01' AND '2011-01-30')
OR (date BETWEEN '2011-02-01' AND '2011-02-30'))
精彩评论