1 1 2 55
1 1 2 232
2, 2, 3, 656
2, 3, 5, 845
2, 3, 5, 840
Want is the structure of the A, B, C, D
1 1 2 55
1 1 2 232
2, 3, 5, 845
2, 3, 5, 840
CodePudding user response:
SELECT * FROM TABLE A
WHERE the EXISTS (SELECT 1 FROM the TABLE WHERE A.A=A AND a.=B AND A.C=C AND a. d. & lt;> D)
CodePudding user response:
The test data-If not object_id (N 'Tempdb for.. # T ') is null
Drop table # T
Go
[A] the Create table # T (int, int [B], [C] int, int) [D]
Insert # T
Select 1,1,2,55 union all
Select 1,1,2,232 union all
Select 2,2,3,656 union all
Select 2,3,5,845 union all
Select 2,3,5,840
Go
- the end of the test data
SELECT a. *
The FROM # T a
The JOIN # T b
ON b.A=a.A
AND b.B=a.
AND the biggest=a.C
AND b.D & lt;> A. d.;
CodePudding user response:
D is the free field don't doCodePudding user response:
The test data-If not object_id (N 'Tempdb for.. # T ') is null
Drop table # T
Go
[A] the Create table # T (int, int [B], [C] int, int) [D]
Insert # T
Select 1,1,2,55 union all
Select 1,1,2,232 union all
Select 2,2,3,656 union all
Select 2,3,5,845 union all
Select 2,3,5,840
Go
- the end of the test data
SELECT a. *
The FROM # T a
The JOIN (SELECT *, ROW_NUMBER () OVER (PARTITION BY A, B ORDER BY GETDATE ()) rn FROM # T) B
ON b.A=a.A
AND b.B=a.
AND the biggest=a.C
AND b.r n> 1;
Results the same
CodePudding user response:
ROW_NUMBER () OVER (PARTITION BY A, B is excuse me this what consciousnessCodePudding user response: