Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这张桌子:
Players: ID (int) Birthday (datetime)
我需要选择 3 个第一名球员,他们在实际月份过生日......我有这个但结果什么都没有......你知道吗?
SELECT * FROM Players WHERE Birthday < DATEADD(month, -2, GETDATE())
您需要在 SQL Server 中使用 DATEPART 函数
SELECT * FROM Players WHERE DATEPART(MM,Birthday) = DATEPART(MM,GETDATE())
使用 SQL Server 语法:
select top 3 * from YourTable where datepart(month, Birthday) = datepart(month, getdate())