我想要在sql查询中连接2个表时然后在结果中 重复的列单元格其中一个重复条目变为null。 我的第一个表是:SQl查询加入并将重复列值设置为null
id corp_code pay_authority_no authority_price status
1 C286 210995 85020000 True
2 C286 210879 61040000 True
3 C139 212475 77708280 True
4 C139 212465 77878320 True
5 C296 216177 101335000 True
13 C321 214526 56680000 True
和第二表是:
id pay_authority_no order_kind order_no
2 210879 Reorder 84182
1 210995 Reorder 83251
4 212465 Sup 459950
3 212475 Sup 459948
15 212475 Sup 65878
13 214526 Reorder 86019
14 214526 Reorder 86020
5 216177 Reorder 83715
而且结果是:
corp_code pay_authority_no authority_price order_no order_kind
C139 212465 77878320 459950 Sup
C139 212475 77708280 459948 Sup
C139 212475 77708280 65878 Sup
C286 210879 61040000 84182 Reorder
C286 210995 85020000 83251 Reorder
C296 216177 101335000 83715 Reorder
C321 214526 56680000 86019 Reorder
C321 214526 56680000 86020 Reorder
我想结果是这样的:
corp_code pay_authority_no authority_price order_no order_kind
C139 212465 77878320 459950 Sup
C139 212475 77708280 459948 Sup
C139 212475 Null or 0 65878 Sup
C286 210879 61040000 84182 Reorder
C286 210995 85020000 83251 Reorder
C296 216177 101335000 83715 Reorder
C321 214526 56680000 86019 Reorder
C321 214526 Null or 0 86020 Reorder
请解决此问题!
总是标记sql服务器的版本 – FLICKER
您可以使用'ROW_NUMBER()OVER(PARTITION BY authority_price ORDER BY任何...)'然后CASE语句,如'CASE WHEN RN = 1 THEN authority_price END'而不是选择authority_price。 – ZLK
我想要这个结果用于stimulreports.net,但是当stimulsoft reports.net设计器处理重复集合时,总和不成立。由于这个原因,必须总结为零重复正确计算总金额 –