请看我的表:
我需要计算总'code1'和总'code2'以及组合code1和code2的总和以及每天的总elapsedTime(timefiledate)。请看我得到的这个输出:
这是我的查询:
SELECT
`Date`,
`Code1`,
`Code2`,
`Total`
FROM
(
SELECT
timefiledate AS `Date`,
(SELECT COUNT(*) FROM tableName WHERE transactionCode= 'code1' AND timefiledate = `date`)AS code1,
(SELECT COUNT(*) FROM tableName WHERE transactionCode= 'code2' AND timefiledate = `date`)AS code2,
(SELECT COUNT(*) FROM tableName WHERE transactionCode IN ('code1', 'code2') AND timefiledate = `date`)AS Total
#Total elapsedTime goes here
FROM bartran
) AS A
WHERE `date` BETWEEN '2013-05-01' AND '2013-05-31'
GROUP BY `date`;
请注意,elapsedTime 类型是“TIME”。我无法获得整个月的总经过时间。请有人给我一个建议。非常感谢!