How can i order below query by whichday so that whichday should start from today which is 19th onwards in the order, any help please:
SELECT MIN(entered_date) as edate, entered_date, SUM(case when entered_date>=‘2020-02-19’ and entered_date<‘2020-03-19’ then 1 else 0 end) AS counter_prev, SUM(case when entered_date>=‘2020-03-19’ and entered_date<=‘2020-04-19’ then 1 else 0 end) AS counter_current, day(entered_date) AS whichday FROM contacts WHERE profile_categories IN(1) and (entered_date>=‘2020-02-19’ and entered_date<=‘2020-04-19’) GROUP BY day(entered_date) ORDER BY whichday ASC
your dates seem to have been enclosed in microsoft word smart quotes, so i changed them to ordinary single quotes
you had entered_date in your SELECT clause alongside MIN(entered_date), but not in your GROUP BY clause, so i removed it
you had unnecessary parentheses in the WHERE clause, so i removed them
finally, you are grouping the day of the month, and both the 29th of february and the 29th of march will be grouped into the same group
so i’m not sure what you actually wanted to do with the day business, and i especially don’t know how you want it sorted
SELECT MIN(entered_date) as edate
, SUM(CASE WHEN entered_date >= '2020-02-19'
AND entered_date < '2020-03-19'
THEN 1 ELSE 0 END) AS counter_prev
, SUM(CASE WHEN entered_date >= '2020-03-19'
AND entered_date <= '2020-04-19'
THEN 1 ELSE 0 END) AS counter_current
, DAY(entered_date) AS whichday
FROM contacts
WHERE profile_categories IN(1)
AND entered_date >= '2020-02-19'
AND entered_date <= '2020-04-19'
GROUP
BY DAY(entered_date)
ORDER
BY whichday ASC
perhaps you could show some sample results to demonstrate how you want this stuff sorted