Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE [dbo].[gupta](
- [a] [int] NULL,
- [b] [int] NULL,
- [c] [int] NULL
- ) ON [PRIMARY]
- INSERT INTO [Test].[dbo].[gupta]([a],[b],[c]) VALUES (1,2,3);
- INSERT INTO [Test].[dbo].[gupta]([a],[b],[c]) VALUES (4,5,6);
- INSERT INTO [Test].[dbo].[gupta]([a],[b],[c]) VALUES (7,8,9);
- INSERT INTO [Test].[dbo].[gupta]([a],[b],[c]) VALUES (10,11,12);
- select MAX(aX),MAX(bX), MAX(cY)
- from
- (
- (
- SELECT row_number() OVER (ORDER BY a ASC) n, a as aX, b as bX, -1 as cY
- FROM [Test].[dbo].[gupta]
- )
- union all
- (
- SELECT row_number() OVER (ORDER BY a DESC) n, -1 as aX, -1 as bx, c as cY
- FROM [Test].[dbo].[gupta]
- )
- ) as U
- group by U.n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement