注册 登录
编程论坛 SQL Server论坛

请教SQL问题

liqiang65194 发布于 2021-10-08 13:49, 2944 次点击
在学习navicate,请教一下,我想求两个日期的差值,admittime是这样的数据2139-09-26 14:16:00,anchor_year是这样的数据2126,网上抄的代码,但是运行不了,求解答
SELECT     
    ad.subject_id
    , ad.hadm_id
    , ad.admittime
    , pa.anchor_age
    , pa.anchor_year
    , DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR) + pa.anchor_age AS age
FROM mimic.mimic_core.admissions ad
INNER JOIN mimic.mimic_core.patients pa
ON ad.subject_id = pa.subject_id
> 错误:  函数 datetime(smallint, integer, integer, integer, integer, integer) 不存在
LINE 7:  , DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1...
                                       ^
HINT:  没有匹配指定名称和参数类型的函数. 您也许需要增加明确的类型转换.

> 时间: 0.002s
0 回复
1