Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| tech-notes:sql:pivot [2022/09/22 13:08] – [Our Original Table] gerardorourke | tech-notes:sql:pivot [2022/09/22 13:21] (current) – [Pivot of our Source Table] gerardorourke | ||
|---|---|---|---|
| Line 29: | Line 29: | ||
| *a single row for each **CollectionID** | *a single row for each **CollectionID** | ||
| - | *have a column for **TransferType** = " | + | *have a column for **TransferType** = " |
| - | *have a column for **TransferType** = " | + | *have a column for **TransferType** = " |
| In this example TransferType can only every be ' | In this example TransferType can only every be ' | ||
| Line 36: | Line 36: | ||
| ==== Our Source Table ==== | ==== Our Source Table ==== | ||
| Since the Header value for these two columns would end up as " | Since the Header value for these two columns would end up as " | ||
| + | Note: this step is not particularly necessary - we could just change the column names at the end - in our final SQL table. | ||
| <code sql> | <code sql> | ||
| Line 79: | Line 80: | ||
| </ | </ | ||
| - | You can see above is a select | + | You can see above is a SELECT |
| <code sql> | <code sql> | ||
| Line 88: | Line 89: | ||
| i.e. we are Pivoting around the column with the data we want to show. In this case the CallsQueuedNow . | i.e. we are Pivoting around the column with the data we want to show. In this case the CallsQueuedNow . | ||
| With a Pivot like you do with Group, you need to do SUM or MAX on the Value. A Max will not change our value. | With a Pivot like you do with Group, you need to do SUM or MAX on the Value. A Max will not change our value. | ||
| - | We then need to decide which CallSQueuedNow values appear under what Columns | + | |
| + | We then need to columns we want the CallSQueuedNow values | ||
| *CIQ_IVR | *CIQ_IVR | ||
| *CIQ_Transfer | *CIQ_Transfer | ||