使用tsql我需要在各种分组和付款状态中调整一些汇总列。
之前:
+---------------+----------+----------------------------+
| policy number | Grouping | £ Amount |
+---------------+----------+----------------------------+
| #123 | a | £1 (for issued payment) |
| #123 | b | £11(for cancelled payment) |
| #123 | a | £21(for cancelled payment) |
| #123 | b | £31(for issued payment) |
+---------------+----------+----------------------------+
渴望之后:
+--------+----------------+----------------+-------------------+-------------------+
| policy | Group a Issued | Group b Issued | Group a cancelled | Group b cancelled |
+--------+----------------+----------------+-------------------+-------------------+
| #123 | £1 | £31 | £21 | £11 |
+--------+----------------+----------------+-------------------+-------------------+
尽管在before表中生成求和列时使用了isnull函数,但我的所有结果都为null。我已经详尽地检查了我的预透视表,并且没有空值。
请注意,因为我必须跨多种付款方式分组,我不得不使用重复的组列。