我有一个附加的数据库,其中我有一个BirthDate列,分为BirthYear,BirthMonth和BirthDayNumber。
例如。对于BirthDate:
Wednesday, May 10, 1899
BirthYear:1899
BirthMonth : 5
BirthDayNumber :10
我想按以下格式对数据库进行排序(月份和日期应按升序排列,如果月份和日期相等,则应按降序对年份进行排序)
01 January 2011
02 January 2012
02 January 2008
05 August 2012
06 September 2001
12 December 1899
请您帮我解决以这种格式显示列表的问题。
答案 0 :(得分:1)
认为这有效
使用此代码
SELECT birthdate FROM testdate
ORDER BY
BirthDayNumber ASC, BirthMonth ASC, BirthYear Desc
答案 1 :(得分:0)
试试这个
SELECT * FROM TABLE ORDER BY BirthYear DESC, BirthDayNumber ASC, BirthMonth ASC
答案 2 :(得分:0)
请尝试下面的查询
SELECT * FROM `tblename` order by BirthYear DESC, BirthMonth ASC,BirthDayNumber ASC
感谢
答案 3 :(得分:0)
尝试类似的东西:
SELECT ROW_NUMBER() OVER (PARTITION BY DT ORDER BY YE DESC, MO ASC, DT ASC) AS NR, DT, MO, YE FROM SOMEDATA
答案 4 :(得分:0)
试试这个
SELECT CONCAT(BirthDayNumber,' ', MonthName(CONCAT('1900-',CONVERT(BirthMonth,char(2)),'-1')), ' ', Birthyear)
FROM table
ORDER BY BirthMonth ASC, BirthDay ASC, BirthYear DESC
答案 5 :(得分:0)
SELECT birthdate FROM testdate
ORDER BY
BirthMonth ASC,BirthDayNumber ASC, BirthYear Desc