Reputation: 11473
l've a table named gst that contain
CREATE TABLE gst (
gst_id INT PRIMARY KEY AUTO_INCREMENT,
month VARCHAR(9) NOT NULL,
price INT NOT NULL
);
INSERT INTO gst
(gst_id, month, price)
VALUES
( 7, February, 3),
( 16, January, 5)
( 17, April, 7),
( 18, March, 2),
I want to display a result in the order of month (ie january, february, march.........):
16 January 5 7 February 3 18 March 2 17 April 7
How can I write the sql query?
Upvotes: 0
Views: 216
Reputation: 1824
Try this....
SELECT DATE_FORMAT(date_col, '%M') as month FROM table ORDER BY month
Try this link also...
Upvotes: 0
Reputation: 254916
... ORDER BY CASE `month`
WHEN 'January' THEN 1
WHEN 'Febduary' THEN 2
...
END
Or
ORDER BY FIND_IN_SET(`month`, 'January,February,March,...')
Or
ORDER BY FIELD(`month`, 'January', 'February', ...)
Upvotes: 2