mysqlsqlbetweendedupeplugin

SQL: Trying and failing to sort data to display certain months


I'm working on a homework assignment, and all has been well until I got to this point. My professor wants me to pull only dates in MARCH, APRIL, and MAY, without using the BETWEEN operator.

NOTE: I'm not getting any errors. I am using EDUPE, which runs MySQL, but has small variances where some things simply won't work.

Question was, is there a way to make the code I have function properly? Or am I going in the wrong direction?

/*Exercise Six*/
SELECT order_id as "Order ID", DATE_FORMAT(order_date, '%M-%d-%Y') as "Order Date"
FROM orders
WHERE order_date IN ('March%', 'April%', 'May%')
ORDER BY order_date ASC;

Solution

  • You can try with date_format again:

    WHERE DATE_FORMAT(order_date, '%M') IN ('March', 'April', 'May')
    

    Or just monthname():

    WHERE MONTHNAME(order_date) IN ('March', 'April', 'May')