I am New in Mysql.I have to find six month interval.Assume latest date is 2022-03-23 if date is between jan to jun then print:
price_date |
---|
2022-03-23 |
2021-12-31 |
2021-06-30 |
2020-12-31 |
2020-06-30 |
else latest date 2022-09-19 is july to december.
price_date |
---|
2022-09-19 |
2022-06-30 |
2021-12-31 |
2021-06-30 |
2020-12-31 |
may be last date value 30,31,23 accordding to my db.
my query is:
SELECT price_date FROM boot.marketprice where f_id=1 and i_id=2 group by year(price_date),month(price_date)in(6,12);
I need this output
price_date |
---|
2022-12-20 |
2022-06-30 |
2021-12-31 |
2020-12-31 |
2020-06-30 |
2019-12-31 |
2019-06-17 |
2018-12-31 |
2018-06-30 |
2017-12-30 |
CodePudding user response:
I want two intervals of a year.
SELECT price_date FROM boot.marketprice where f_id=1 and i_id=2 group by year(price_date),month(price_date)=6;
if you want every quarter data
SELECT price_date FROM boot.marketprice where f_id=1 and i_id=2 group by year(price_date),QUARTER(price_date);
if you want every week's data
SELECT price_date FROM boot.marketprice where f_id=1 and i_id=2 group by year(price_date),week(price_date);