EDIT: I need the overall total in there subtracting both direct and indirect minutes.
I’m trying to SUM M. Minutes as an alias “dminutes”. Then, take the SUM of M.minutes again and subtract M.minutes that have “indirect” column value (and give it “inminutes” alias). However, it’s showing me null, so the syntax is wrong. Suggestions?
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 statement:
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
I think something like this should work.
You might have to tweak it a little.