发布网友 发布时间:2022-05-04 14:50
共2个回答
热心网友 时间:2022-05-04 16:20
你这个需求很不明确追答可以通过distinct来获取,就可以跳开相同的AID
示例
create table a
(
id int,
amt float,
xid int
)
go
insert into a select 1, 100, 1
insert into a select 2, 100, 1
insert into a select 3, 100, 1
insert into a select 3, 100, 2
insert into a select 4, 100, 1
insert into a select 5, 100, 1
insert into a select 6, 100, 1
insert into a select 3, 100, 2
go
select distinct xid, sum(amt), count(xid) from
(select distinct * from a) b group by xid
但是我看到你相同aid的后面内容不一样的
好像不好处理,还是写个函数,用游标处理吧