表格如下: -
ID AMOUNT PAID
1 500 100
1 500 50
1 500 200
2 1000 300
3 800 500
- 我想打印ID 1值应为零,除了第一个值,如: -
ID AMOUNT PAID
1 500 100
1 0 50
1 0 200
2 1000 300
3 800 500
- 而不是重复值必须用零替换
答案 0 :(得分:1)
最好在应用层完成。假设您有一个排序列,可以在SQL中执行:
select id,
(case when row_number() over (partition by id order by ??) = 1
then amount
else 0
end) as amount,
paid
from t
order by id, ??;
??
表示用于订购的列。