Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
寻找有关如何结合按项目分组的分组方式的帮助。有人可以在这里提供帮助吗?
下面的示例:具有交易金额的相同状态的多笔交易。我想将事务 A+B 组合在一起,但将 C 事务分开。
数据:
Transaction Type, State, Amount A, SC, 43.00 B, SC, 44.00 C, SC, 45.00 B, SC, 46.00
我希望输出看起来像:
A+B, SC, 133.00 C, SC, 45.00
怎么样
SELECT CASE WHEN [Transaction Type] IN ('A','B') THEN 'A+B' ELSE [Transaction Type] END [Transaction Type], State, SUM(Amount) Total FROM MyTable GROUP BY CASE WHEN [Transaction Type] IN ('A','B') THEN 'A+B' ELSE [Transaction Type] END, State
?