如何通过dob订购,然后订购姓氏,然后在同一年龄段的名字?

时间:2012-01-08 13:43:03

标签: mysql

到目前为止,我的查询看起来像这样:

SELECT CONCAT (child_fname,' ',child_sname) AS 'Name', child_dob AS 'DoB',
FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25) as 'Age'
FROM Child
ORDER BY child_dob, child_sname, child_fname;

我已设法订购Age但不知道如何订购child_sname,然后child_fname订购相同的年龄?

3 个答案:

答案 0 :(得分:0)

我不确定你的问题在哪里..

这将按年龄排序,然后按sname,然后是我的fname

SELECT CONCAT (child_fname,' ',child_sname) AS 'Name', child_dob AS 'DoB',
FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25) as 'Age'
FROM Child
ORDER BY FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25), child_sname, child_fname;

答案 1 :(得分:0)

SELECT CONCAT (child_fname,' ',child_sname) AS 'Name', child_dob AS 'DoB',
FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25) as 'Age'
FROM Child
ORDER BY FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25), child_sname, child_fname;

答案 2 :(得分:0)

您可以对多个列进行排序,您可以按不同的方向对不同的列进行排序asc / desc,如下所示:

  SELECT 
    CONCAT (child_fname,' ',child_sname) aS Name,
    child_dob aS DoB,
    FLOOR(DATEDIFF(CURRENT_DATE, child_dob)/365.25) as Age
    FROM Child
    ORDER BY Age,child_sname, child_fname;