How to get max and min of columns per row for pivoted table?
问题 Big thanks to @JohnCappelletti as he's shown how to pivot a table. This is a sample data: DECLARE @OperatorPrice TABLE (ID int NOT NULL, OperatorId INT NULL, Price NUMERIC(18,3) NULL, FName VARCHAR(50) NULL) INSERT INTO @OperatorPrice ( ID, OperatorId, Price, FName ) VALUES (226, 996, 22954,'Operator1') , (266, 1016, 79011.2, 'Operator3') , (112, 1029, 14869, 'Operator4') , (112, 996, 22954, 'Operator1') , (93, 1031, 10568.96, 'Operator5') DECLARE @TR TABLE ( ID varchar(25) NULL , MinPrice