LINE_INVOICE PAYMENT_SOURCE SOURCE_PMT_ID
-1 Payment Received 7369442
1 Payment Received 7369442
2 Payment Received 7369442
3 Payment Received 7369442
4 Payment Received 7369442
5 Payment Received 7369442
6 Payment Received 7369442
7 Payment Received 7369442
8 Payment Received 7369442
9 Payment Received 7369442
10 Payment Received 7369442
11 Payment Received 7369442
12 Payment Received 7369442
我想删除'-1'行,只要“行发票列”中有任何其他数字。这对于每个源付款id都是特定的。如果没有“1”行,则返回-1。如何在我的sql查询中捕获它?
3条答案
按热度按时间ui7jx7zq1#
我怀疑您需要窗口函数:
Windows
max()
在子查询中,检查是否至少存在一行具有相同的source_pmt_id
和一个line_invoice
值而不是-1
. 外部查询使用该信息筛选出line_invoice
有价值-1
,同时保留那些没有其他值的source_pmt_id
.xpszyzbs2#
单向窗口功能:
或者,如果没有子查询:
qaxu7uf23#
假设-1是最低的数字,并且第1行从那里开始上升:
这把小提琴展示了它的工作原理。