目前我的查询看起来像这样
Select A, B, count (C) as Quantity, sum (D) as Fee,
(select ABC from Mappings where MT = A) as 'Dog',
(select ACD from Mappings where MT = A) as 'Cat'
from @mt
where A in (select MT from Mappings where AED in (@Cli))
group by A, B
目前我的数据正在对A上的数据进行计数和求和,但我希望数据能够被Cat计算和驯服。
有没有办法将数据分组到另一列
我正在使用t-sql
感谢任何帮助
答案 0 :(得分:0)
由于A
或B
没有进行汇总计算,因此它们都需要保留在GROUP BY
子句中。如果您在最终结果中不需要那些(或“狗”),您可以尝试以下方法:
Select (select ACD from Mappings where MT = A) as 'Cat'
count (C) as Quantity,
sum (D) as Fee
from @mt
where A in (select MT from Mappings where AED in (@Cli))
group by (select ACD from Mappings where MT = A)