order a query by days of week starting with monday
hello. suppose a table XYZ has a column buydate. and there are 14 rows in it, 2 for each day of the week. if i would like to sort a query by days of the week, but starting from monday, how would i be able to do that? i have tried this query :
select * from XYZ order by to_char(buydate,'D') ;
this would bring sunday as the first row.
i dont want sunday as the first row, i want monday.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
You can also subtract one day from the date field where Sunday becomes Saturday and Monday becomes Sunday hence it would sort the days from Monday to Sunday.
Code:
select * from XYZ order by to_char(buydate-1,'D') ;
Bookmarks