我有查询,它按组计算活跃客户,并且必须按组计算皮卡。
SELECT [Category] = ISNULL(c.Category, 'Total'),
COUNT (hs.ClientID) as '3 Mo Clients',
(COUNT (hs.ClientID))/3 as MoAVG
,(select COUNT(PickupID)from Pickup where PickupDate between '2013-01-01' and '2013-03-30' group by CategCode) as '3 Mo Picups'
FROM Category c
LEFT JOIN history hs
ON hs.CategCode = c.CategCode
where ReccordDate between '2013-01-01' and '2013-03-30'
GROUP BY Category
WITH ROLLUP
此查询引发错误:Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
如果我没有在 4 行中使用 group by,它可以工作,但没有按组划分拾音器。这是示例在代码的 4 行中没有 group by 子句的情况下它是如何工作的
任何想法如何解决它?