CREATE TABLE [dbo].[theRecords](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
[thegroup] [varchar](50) NULL,
[balance] [int] NULL,
)
GO
insert into theRecords values('blue',1,10)
insert into theRecords values('green',1,20)
insert into theRecords values('yellow',2,5)
insert into theRecords values('red',2,4)
insert into theRecords values('white',3,10)
insert into theRecords values('black',4,10)
まず、各グループの残高の合計を取得したい。次に、グループが 1 つしかない名前の場合、名前を保持し、同じグループに属する名前の名前もグループ名に変更する必要があります。
name | balance
1 30
2 9
white 10
black 10