得到总和(a + b-c)和一些单独的字段,比如从表中选择名称?

时间:2015-11-23 08:50:36

标签: postgresql

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

0 个答案:

没有答案