DECLARE @TBL AS TABLE
(
ID INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
First VARCHAR(10),
Last VARCHAR(10),
Address VARCHAR(30),
Quantity INT,
Price INT,
Discount VARCHAR(10)
);
INSERT @TBL (First, Last, Address, Quantity, Price, Discount )
VALUES
('rolp', 'Gaflp', '24 street', 1, 155, '10%'),
('rolp', 'Gaflp', '24 street', 3, 202, '5%'),
('rolp', 'Gaflp', '24 street', 4, 312, '6%');
WITH CTE AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY First, Last, Address ORDER BY Quantity) AS Row
FROM @TBL
)
SELECT ID,
CASE WHEN Row = 1 THEN First ELSE '' END AS First,
CASE WHEN Row = 1 THEN Last ELSE '' END AS Last,
CASE WHEN Row = 1 THEN Address ELSE '' END AS Address,
Quantity, Price, Discount
FROM CTE;
以下代码应该工作,在内存表中测试: