October 22, 2024
Chicago 12, Melborne City, USA
SQL

How to sort the Date Names accordingly using SQL


I have this code that successfully displayed 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.
enter image description here

Any idea? Thank you in advance.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video