当我尝试运行下面的脚本时,我很难过。错误消息:
Order by子句在视图和内联函数中无效
insert into cc.s
(
id,
encid,
a_name,
a_des,
a_type,
a_value,
d_create
)
select
id,
encid,
'days_charge',
'Days 43',
'int',
(
select
datediff(day,t_dis,a.ts_it)
from
cc.enoun
where
encid <> a.encid
and id=a.pe_id
and a_source='tEst'
and a.ts_admit > t_dis
order by
tdischarge desc limit 1
) as attr_value,
getdate()
from
cc.s a
GO
答案 0 :(得分:0)
在您的脚本中,您尝试使用SELECT语句来获取a_value。这里你的问题是这个select语句是你的内联函数。由于内联函数不具有ORDER BY子句,因此您只需将其删除即可。
insert into cc.s(id, encid, a_name, a_des, a_type, a_value, d_create)
select id, encid,'days_charge','Days 43','int',
(select datediff(day,t_dis,a.ts_it) from cc.enoun where encid<>a.encid and id=a.pe_id and a_source='tEst' and a.ts_admit>t_dis)
as attr_value,
getdate()
from cc.s a
GO
还要确保您的内联语句仅返回1个值。由于您尝试使用ORDER BY子句,这可能意味着它返回多个结果。