select id as identity(int,1,1),* into #t from tb
Go
select No,name=(select name from #t where id=a.id),Price,Sum(Mum),Total=(select total from #t where id=a.id)
from #t a
groub by No,Price
Go
drop table #t
Go
select No,name=(select name from #t where id=a.id),Price,Sum(Mum),Total=(select total from #t where id=a.id)
from #t a
groub by No,Price
Go
drop table #t
group by No,Name,Price
group by No,Price
Insert into tb
select '111-1','AAAAAA','2.00','6','12.00'
union all select '111-2','AAAAAA','2.50','4','10.00'
union all select '112','BBBBBB','3.00','3','9.00'
union all select '114','CCCCCC','4.00','1','4.00'
union all select '114','CCCCCC','4.50','2','9.00'
union all select '114','CCCCCC','4.00','2','12.00'select No,Name,Price,Mum=sum(Mum),Total=sum(Total) from tb
group by No,Name,Price--結果
No Name Price Mum Total
-------------------------------------------
111-1 AAAAAA 2.00 6 12.00
111-2 AAAAAA 2.50 4 10.00
112 BBBBBB 3.00 3 9.00
114 CCCCCC 4.00 3 16.00 ---->這里不應該12.00
114 CCCCCC 4.50 2 9.00
name 字段是不可以直接列出来的
group by No,[Name],Price
group by No,[Name],Price
group by [No],[Name],Price
group by No,Name,Price
!
其中有的no 是不一样的。但是name是相同的。