0

我正在尝试从单个表中生成数据,该表创建一个报告,显示位置 a、b、c 在上一时期(@dt)发生了多少次。

我可以使单个 SELECT 查询工作,但无法弄清楚如何将它们组合在一起并生成完整的报告。错误是 1241:操作数应该包含 1 列,我已经花了一个小时来处理以前的答案,但完全被卡住了。

SELECT (
SELECT DISTINCT pid, SUM(location like '%a%') FROM db.t WHERE (date > @dt) GROUP BY pid)
 AS 'a', (
SELECT DISTINCT pid, SUM(location like '%b%') FROM db.t WHERE (date > @dt) GROUP BY pid)
 AS 'b', (
SELECT DISTINCT pid, SUM(location like '%c%') FROM db.t WHERE (date > @dt) GROUP BY pid)
 AS 'c';
4

1 回答 1

0

您在寻找每计数pid吗?如果是这样,这是一个更简单的查询:

 SELECT pid, SUM(location like '%a%') as As,
        SUM(location like '%b%') as Bs,
        SUM(location like '%c%') as Cs
 FROM db.t
 WHERE (date > @dt)
 GROUP BY pid
于 2013-06-18T16:43:21.653 回答