Select Query to find Duplicated Values from the table
本问题已经有最佳答案,请猛点这里访问。
如何从表中获取重复信息
1 2 3 4 5 6 7 8 9 | Docnum |CustomerName| DocumentValue| DATE 101 |ABC | 10 | 14-04-18 102 |ABC | 10 | 14-04-18 103 |LMN | 11 | 14-04-18 104 |KFB | 11 | 15-04-18 105 |KFB | 12 | 16-04-18 106 |KFB | 12 | 16-04-18 107 |KFB | 12 | 17-04-18 108 |XYZ | 12 | 17-04-18 |
结果应该是:
1 2 3 4 5 6 | Docnum |CustomerName| DocumentValue| DATE | COUNT 101 |ABC | 10 | 14-04-18 | 2 102 |ABC | 10 | 14-04-18 | 2 105 |KFB | 12 | 16-04-18 | 3 106 |KFB | 12 | 16-04-18 | 3 107 |KFB | 12 | 16-04-18 | 3 |
如果要根据客户,文档值和日期查找重复项并保留docnum,可以使用窗口功能。
1 2 3 4 5 | SELECT Docnum , CustomerName, DocumentValue, DATE, c FROM ( SELECT Docnum , CustomerName, DocumentValue, DATE, COUNT(1) OVER(PARTITION BY CustomerName, DocumentValue, DATE) AS c ) t WHERE c >= 1; |