SELECT time.EmpID, time.Date,
SUM(MinutesatState) AS active FROM time WHERE State = 'active'
GROUP BY time.EmpID, time.Date;
以上查询工作
SELECT time.EmpID, time.Date,
SUM(MinutesatState) AS idle FROM time WHERE State = 'idle'
GROUP BY time.EmpID, time.Date;
上述查询也适用
但是当我在同一个语句中运行两个查询时,它就不起作用了
SELECT time.EmpID, time.Date,
SUM(MinutesatState) AS active FROM time WHERE State = 'active'
SUM(MinutesatState) AS idle FROM time WHERE State = 'idle'
GROUP BY time.EmpID, time.Date;
2条答案
按热度按时间gab6jxml1#
可以将状态包含在GROUPBY列中。
kgsdhlau2#
上一个查询语法错误。你不能使用
FROM
像这样的条款。您正在使用CASE..WHEN
条款。