编辑:我需要那里的总总数减去直接和间接分钟数。
我正在尝试 SUM M. Minutes 作为别名“dminutes”。然后,再次取 M.minutes 的 SUM 并减去具有“间接”列值的 M.minutes(并给它“inminutes”别名)。但是,它显示为 null,因此语法错误。建议?
table = tasks
column = task_type
Example:
M.minutes total = 60 minutes
M. minutes (with "direct" task_type column value) = 50 minutes (AS dminutes)
M. minutes (with "indirect" task_type column value) = 10 minutes (AS inminutes)
SQL 语句:
SELECT
U.user_name,
SUM(M.minutes) as dminutes,
ROUND(SUM(M.minutes))-(SELECT (SUM(M.minutes)) from summary s WHERE ta.task_type='indirect') as inminutes
FROM summary S
JOIN users U ON U.user_id = S.user_id
JOIN tasks TA ON TA.task_id = S.task_id
JOIN minutes M ON M.minutes_id = S.minutes_id
WHERE DATE(submit_date) = curdate()
AND TIME(submit_date) BETWEEN '00:00:01' and '23:59:59'
GROUP BY U.user_name
LIMIT 0 , 30