我正在尝试从单个表生成数据,该表创建一个报告,显示上一个时间段(@dt)中位置a,b,c的次数。
我可以使单个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';
答案 0 :(得分: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