SELECT (
SELECT SUM(qty)
FROM sk_lgr_hd
WHERE item_id = 4
AND tra_type = 'OS'
AND dept_id = 7
) + (
SELECT SUM(qty)
FROM sk_lgr_hd
WHERE item_id = 4
AND tra_type = 'IR'
AND dept_id = 7
) - (
SELECT SUM(qty)
FROM sk_lgr_hd
WHERE item_id = 4
AND tra_type = 'IS'
AND dept_id = 7
)
我可以得到总和我需要得到dept_id,tra_type,id,.. 我需要这样的东西。
sum dept_id id
20 2 3