Finding the sum of sales and returning the max of name

Hi All,

Hope you are doing well!...I am trying to find the sum of sales by ID and returning only the max of the name as there are multiple names for a single ID..Please find the DDL for the input and the output tables..Can you please help me here..

Input table

Create table ##input

(ID int,

name varchar(50),

sales int)

insert into ##input values

('3051'Department of psychology ','382'),

('3051'psychology department of medicine','4087')

output table

create table ##output

(ID int,

name varchar(50),

sales int)

insert into ##output values

('3051','psychology department of medicine',4469')

Thanks,

Arun


SELECT ID, MAX(name) AS name, SUM(sales) AS sales
FROM ##input
GROUP BY ID