0

我有一个附加的数据库,其中我有一个 BirthDate 列,该列分为 BirthYear、BirthMonth 和 BirthDayNumber。

数据库映像

例如。对于出生日期:

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 

您能帮我查询以这种格式显示列表的查询吗?

4

6 回答 6

1

认为这行得通

SQLFiddle

使用此代码

SELECT birthdate FROM testdate 
ORDER BY 
BirthDayNumber ASC, BirthMonth ASC, BirthYear Desc
于 2012-10-04T08:18:01.523 回答
0

尝试这个

SELECT CONCAT(BirthDayNumber,' ', MonthName(CONCAT('1900-',CONVERT(BirthMonth,char(2)),'-1')), ' ', Birthyear)
FROM table
ORDER BY BirthMonth ASC, BirthDay ASC, BirthYear DESC
于 2012-10-04T08:13:56.517 回答
0

尝试这样的事情:

SELECT ROW_NUMBER() OVER (PARTITION BY DT ORDER BY YE DESC, MO ASC, DT ASC) AS NR, DT, MO, YE FROM SOMEDATA
于 2012-10-04T07:44:27.317 回答
0
SELECT birthdate FROM testdate 
ORDER BY 
BirthMonth  ASC,BirthDayNumber  ASC, BirthYear Desc
于 2012-10-04T08:42:07.010 回答
0

尝试这个

SELECT * FROM TABLE ORDER BY BirthYear DESC, BirthDayNumber ASC, BirthMonth ASC
于 2012-10-04T05:22:22.690 回答
0

请尝试下面给出的查询

SELECT * FROM `tblename`  order by BirthYear DESC, BirthMonth ASC,BirthDayNumber ASC

谢谢

于 2012-10-04T05:36:44.687 回答