select min(id) as id, name, sum(num) as num from tb group by name
SELECT MIN(ID)ID,NAME,SUM(NUM)NUM FROM TB GROUP BY NAME
create funcation test(@name) return int as select sum(num) from tb where name=@num select id,name,test(name) from tb A where not exist (select 1 from tb B where A.name=B.name and A.id>B.id)
SELECT MIN(ID)ID,NAME,SUM(NUM)NUM FROM TB GROUP BY NAME
min(id) as id,
name,
sum(num) as num
from
tb
group by
name
return int
as
select sum(num)
from tb
where name=@num
select id,name,test(name)
from tb A
where not exist (select 1 from tb B where A.name=B.name and A.id>B.id)