首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

高手帮忙改1条SQL ,提示异常! 在包含外部引用的被聚合表达式中指定了多个列

2013-04-02 
高手帮忙改1条SQL ,提示错误! 在包含外部引用的被聚合表达式中指定了多个列。 --在包含外部引用的被聚合表

高手帮忙改1条SQL ,提示错误! 在包含外部引用的被聚合表达式中指定了多个列。


 --在包含外部引用的被聚合表达式中指定了多个列。如果被聚合的表达式包含外部引用,那么该外部引用就必须是该表达式中所引用的唯一的一列

select a.empid,a.card_date,a.one_ex_from,a.one_cal_from,one_from from hr_card_day a
 outer apply (
    select min(case when wdatetime >= a.one_ex_from and wdatetime <=a.one_cal_from then wdatetime else null end) on_from from HR_WorkCardSource_me  --这个为什么提示错误?
 -- select min(wdatetime) on_from from HR_WorkCardSource_me  --(这样OK)
 -- select case when wdatetime >= a.one_ex_from and wdatetime <=a.one_cal_from then wdatetime else null end on_from from HR_WorkCardSource_me  --(这样也OK)
   where cardnum=a.empid and wdatetime=a.VAL_FROM and wdatetime<=a.VAL_TO )c
 where a.empid = '000107' and card_date > '2012-12-31' and card_date < '2013-02-01' 
order by card_date desc



[解决办法]
elect a.empid,a.card_date,a.one_ex_from,a.one_cal_from,one_from from hr_card_day a
 outer apply (
    select min(wdatetime) on_from from HR_WorkCardSource_me  --这个为什么提示错误?
   where cardnum=a.empid and wdatetime=a.VAL_FROM and wdatetime<=a.VAL_TO 
and wdatetime >= a.one_ex_from and wdatetime <=a.one_cal_from
)c
 where a.empid = '000107' and card_date > '2012-12-31' and card_date < '2013-02-01' 
order by card_date desc

热点排行
Bad Request.