OiO.lk Blog SQL Sort by Date Day Names
SQL

Sort by Date Day Names


I have this code that successfully displays the number of orders according to the day-name of the week. However, I wanted to display the days name sorted accordingly.
I have this code below:

SELECT 
    DATENAME(dw, orderDate) AS day_of_week, 
    COUNT(orderID) AS total_orders
FROM 
    Orders
GROUP BY 
    DATENAME(dw, orderDate)

Here’s the output: But I wanted the Days(name) sorted from Monday, Tuesday, Wednesday.. and so on.

Any idea? Thank you in advance.



You need to sign in to view this answers

Exit mobile version