大家帮忙好急................
有一表A
type id name price amount money
A 1 SS 1.2 2 2.4
A 3 BB 3 2 6
B 4 YY 9 1 9
C 6 oo 3 3 9
要得到
type name price amount money
SS 1.2 2 2.4
BB 3 2 6
A合计 8.4
YY 9 1 9
B合计 9
oo 3 3 9
C合计 9
总合计 26.4
------解决方案--------------------Create Table A
(type Varchar(10),
id Int,
name Varchar(10),
price Numeric(10, 1),
amount Int,
[money] Numeric(10, 1))
Insert A Select 'A ', 1, 'SS ', 1.2, 2, 2.4
Union All Select 'A ', 3, 'BB ', 3, 2, 6
Union All Select 'B ', 4, 'YY ', 9, 1, 9
Union All Select 'C ', 6, 'oo ', 3, 3, 9
GO
Select
(Case When Grouping(type) = 1 Then N '总合计 ' Else Case When Grouping(name) = 1 Then type + N '合计 ' Else ' ' End End) As type,
name,
price,