我有这个选择查询来显示一个表
select distinct
a.afdeling as AFD,
convert(varchar(10),DateAdd(Day, DateDiff(Day, 0, a.datetrans) , 0),103) as datetrans ,
convert(varchar(10),DateAdd(Day, DateDiff(Day, 0, a.doe ), 0),103) as inputdate,
(select COUNT(distinct a.DOE) from detail a left join
estate b on a.CodeEstate=b.Code group by
a.afdeling, a.datetrans , convert(varchar(10),DateAdd(Day, DateDiff(Day, 0, a.DOE ) ,0),103)
) as total ,
datediff(DAY,a.datetrans,a.DOE) as variant ,
GetDiffStatus(a.datetrans,a.DOE) as status from
detail a left join
estate b on a.CodeEstate=b.Code where b.name='Estate 1' and convert(varchar(10),DateAdd(Day, Datediff(Day, 0,
a.datetrans), 0),103) between '01/01/2013' and '31/01/2013' Group
BY a.datetrans, a.doe,DateDiff(Day, 0, a.doe),a.afdeling order by
a.afdeling, a.datetrans, a.inputdate , a.variant,
a.status
我想要做的是计算一个表中相同日期的总 DOE,基于在表详细信息中有键的其他表(房地产)中的名称,但是当我使用该查询时,它显示错误子查询返回超过1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
如何解决这个问题,我使用的是 SQL Server 2008 r2,谢谢