Hi smile,
Please refer below query.
SQL
DECLARE @TestDemo AS TABLE(AdmissionNo VARCHAR(5), NetBal INT, Paid INT, RemBal INT)
INSERT INTO @TestDemo VALUES('R-01',700,400,300)
INSERT INTO @TestDemo VALUES('R-02',700,300 ,400)
INSERT INTO @TestDemo VALUES('R-02',400,400,0)
INSERT INTO @TestDemo VALUES('R-03',700 ,600 ,100)
INSERT INTO @TestDemo VALUES('R-04',700 ,700,0)
INSERT INTO @TestDemo VALUES('R-05',700,700,0)
INSERT INTO @TestDemo VALUES('R-06',700,700,0)
SELECT * FROM @TestDemo
WHERE RemBal !=0 AND AdmissionNo NOT IN (SELECT AdmissionNo FROM @TestDemo WHERE RemBal = 0)
Screenshot
AdmissionNo |
NetBal |
Paid |
RemBal |
R-01 |
700 |
400 |
300 |
R-03 |
700 |
600 |
100 |