我这样做,但结果给了我30年不到30年的所有名字。
这是数据库:
我使用了这段代码 - 哪里错了?
SELECT
GETDATE () AS FirstName,
FirstName, LastName,
DATEADD(DD, 30, GETDATE()) AS [DateOfDonate- DateOfBirth],
DATEADD(DD, 1-1-2000, GETDATE()) AS [DonateOfDate]
FROM
Donor
我需要解决这个问题:找出年龄超过30岁且自2000年1月1日以来捐赠的捐赠者姓名
答案 0 :(得分:0)
SELECT
*
FROM
donor
WHERE
[date-of-birth] <= DATEADD(YEAR, -30, GETDATE()) -- Anyone born more than 30 years ago
AND [date-of-donate] >= '2000-01-01' -- Anyone that donated since 1st Jan 2000
答案 1 :(得分:-1)
对不起以前的错字。我用实际字段计算,然后用你的字母替换,导致混乱。 请使用以下
cast(datediff(Year,Date-Of-Birth,getdate()) as nvarchar(100))
+ ' Years , '
+ cast(datediff(Month,Date-Of-Birth,getdate())%12 as nvarchar(100))
+ ' months and '
+ cast(datediff(day,Date-Of-Birth,getdate()) as nvarchar(100))
+' days '
答案 2 :(得分:-1)
select FirstName+" "+ LastName from Donor
where datediff(year,Date-of-birth,getdate()) >30 and Date-of-donate>
convert(date,'Date-of-donate',103)=convert(date,'Date-of-
donate',103)='1/1/2000'
这对你有用