I have following table which saves sales data for specific week of a year.
Sales
week | year | value
50 | 2011 | 150
51 | 2011 | 151
52 | 2011 | 152
1 | 2012 | 170
2 | 2012 | 190
3 | 2012 | 180
4 | 2012 | 160
5 | 2012 | 170
6 | 2012 | 290
I want to find records which lies between week1 of year1 and week2 of year2.
for example
Having little experience in sQL, I tried following query which works for case 2 but not for case 1.
SELECT * from sales WHERE (week >= 1 AND year >= 2012) AND (week <= 6 AND year <= 2012 )
Looks like grouping of condition does not work as I understand. It takes as if there are no grouping of conditions.
select *
from
(
Select *, year*100 + week as yearweek
from table
) v
where yearweek between 201150 and 201205
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With