I suspect you just need this:CREATE TABLE dbo.Orders (
ORDER_NUMBER numeric(15, 2) NOT NULL CONSTRAINT [DF_Orders_ORDER_NUMBER] DEFAULT ((0)),
ST_ID numeric(10) NOT NULL CONSTRAINT [DF_Orders_ST_ID] DEFAULT ((0)),
TOTAL_PAYMENTS money NOT NULL CONSTRAINT [DF_Orders_TOTAL_PAYMENTS] DEFAULT ((0))
CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED
(
ORDER_NUMBER ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
);
GO
SET ANSI_PADDING ON;
GO
INSERT INTO dbo.Orders (ORDER_NUMBER, ST_ID, TOTAL_PAYMENTS)
VALUES (20650917.00,111156,220.50)
,(21888549.00,111156,220.50)
,(23475974.00,111156,245.00)
,(15438023.00,115240,97.00)
,(26580872.00,115240,166.00)
,(17064426.00,122994,117.50)
,(21887826.00,122994,121.00)
,(26467822.00,122994,130.00)
,(16240398.00,132943,117.50)
,(20445595.00,132943,172.50)
,(16694116.00,134513,245.00)
,(17437801.00,134513,220.50)
,(21784193.00,134513,247.50);
SELECT TOP(1) ST_ID, SUM(TOTAL_PAYMENTS) AS highest
FROM dbo.Orders
GROUP BY ST_ID
ORDER BY SUM(TOTAL_PAYMENTS) DESC;
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)