Forum Discussion
nrajeshkumars
Feb 12, 2024Copper Contributor
SQL query to retrieve Expected result
Hi ,
From the below table and insert value script i need to derive the expected result value.
Required help in this .
CREATE TABLE #data(MainID int NOT NULL,
Component varchar(10) NOT NULL,
Value varchar(10) NOT NULL,
Seqno int
)
go
INSERT #data (MainID, Component, Value,Seqno)
VALUES(1, 'ALPHA', 'Y',1),
(1, 'BETA', 'N',2),
(1, 'GAMMA', 'N',3),
(1, 'DELTA', 'Y',4),
(1, 'EPSILON', 'Y',5),
(2, 'London', 'N',1),
(2, 'New York', 'Y',2),
(2, 'Mumbai', 'N',3)
go
Required result:
| MainID | Component | Value | Seqno | Expecting result |
| 1 | ALPHA | Y | 1 | 1 |
| 1 | BETA | N | 2 | 2 |
| 1 | GAMMA | N | 3 | 2 |
| 1 | DELTA | Y | 4 | 3 |
| 1 | EPSILON | Y | 5 | 3 |
| 2 | London | N | 1 | 1 |
| 2 | New York | Y | 2 | 2 |
| 2 | Mumbai | N | 3 | 3 |
1 Reply
- olafhelperBronze ContributorAnd what's the logic for the "expected result"; just by having a look at I don't get it?