gpt4 book ai didi

sql - 按生日排序,不考虑年份

转载 作者:行者123 更新时间:2023-12-03 03:00:26 25 4
gpt4 key购买 nike

如何在完全不考虑年份的情况下按生日排序的查询。我需要从今天的 ASC 或 DESC 中删除/忽略年份和 ORDER BY 出生日期月份和出生日期。

以下内容不起作用,因为生日年份会起作用。下面的示例显示了考虑年份时会发生什么:

John   01/02/1974
Billy 11/15/2000
Ally 06/25/2008

SELECT * FROM users ORDER BY birthdate

按生日订购时的预期结果:

John   01/02/1974
Ally 06/25/2008
Billy 11/15/2000

最佳答案

编辑:@AaronBertrand 的评论是正确的,day-of-year不适用于闰年。你可以使用他的解决方案。另一种方法是按月和日排序,例如:

SELECT * FROM users ORDER BY month(birthdate), day(birthdate)

关于sql - 按生日排序,不考虑年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11213161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com