我有这样的数据:
Order No. Name Date Unit Price Freight
001 ABC 1-16 232 25
001 ABC 1-16 55 25
001 ABC 1-16 156 25
002 DEF 2-5 478 16
002 DEF 2-5 356 16
我只想让运费在我的桌子上显示一次,结果会是:
Order No. Name Date Unit Price Freight
001 ABC 1-16 232 25
001 ABC 1-16 55 0
001 ABC 1-16 156 0
002 DEF 2-5 478 16
002 DEF 2-5 356 0
请帮我处理这个
发布于 2015-05-29 19:34:34
下面是一个获取所需内容的查询:
SELECT
order_no, name, theDate, unit_price,
case
when row_number() OVER (PARTITION by order_no ORDER BY order_no) = 1 then freight
else 0
end as freight
from yourTable
这将查看每个订单编号的所有行,并提供行号。如果它是该订单的第1行,它使用运费列的值,否则它使用0。
请注意,我假设同一订单号的所有行的运费值是相同的。
https://stackoverflow.com/questions/30537467
复制相似问题