-1

我正在尝试创建一个总行,该行从列中获取项目并显示总字段中的差异而不是总和。这在 SQL 中甚至可能吗?

SELECT P.Part_Number, P.Units_On_Hand 
FROM Part AS P 
WHERE P.Part_Number IN ('AX12', 'AZ52')

这是我当前必须显示需要处理的项目的查询。如何修改它以合并一个总列以显示差异?

4

1 回答 1

0
;with cte as
(
    select part_number, SUM(units_on_hand) total
    from yourtable
    where part_number IN ('AX12', 'AZ52')
    group by part_number
)
    select t1.part_number, t2.part_number, abs(t1.total-t2.total)
    from cte t1
        inner join cte t2
        on t1.part_number<t2.part_number
于 2012-10-30T09:27:58.970 回答