【发布时间】:2013-03-12 22:38:36
【问题描述】:
我有一个查询,它按组计算活跃客户,并且必须按组计算取货量。
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 子句的示例如何工作
任何想法如何解决它?
【问题讨论】:
-
傻评:3月有31天。
-
@ypercube 现在不重要,它会从用户那里获取数据。是的
CategCode在取货中 -
你为什么不加入皮卡而不是使用子查询?
标签: sql sql-server-2008 group-by