SELECT y ,
( SELECT MIN(x)
FROM user997112 i
WHERE i.Y = o.y
AND i.VALUE = o.VALUE
) AS x ,
value
FROM ( SELECT y ,
MIN(VALUE) AS value
FROM dbo.user997112
GROUP BY y
) AS o
这是我使用的架构
CREATE TABLE [dbo].[user997112](
[x] [int] NULL,
[y] [int] NULL,
[VALUE] [decimal](5, 2) NULL
)
GO
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (0, 0, CAST(0.38 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (1, 0, CAST(0.72 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (2, 0, CAST(0.13 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (3, 0, CAST(0.45 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (0, 1, CAST(0.52 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (1, 1, CAST(0.23 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (2, 1, CAST(0.84 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (3, 1, CAST(0.15 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (0, 2, CAST(0.52 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (1, 2, CAST(0.04 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (2, 2, CAST(0.04 AS Decimal(5, 2)))
INSERT [dbo].[user997112] ([x], [y], [VALUE]) VALUES (3, 2, CAST(0.15 AS Decimal(5, 2)))