Note that there are some explanatory texts on larger screens.

plurals
  1. PORows Into Columns and Grouping
    primarykey
    data
    text
    <p>I have a query that looks like this:</p> <pre><code>SELECT OrganizationName, OrganizationID, ReceivableStatus, InvoiceFee FROM v_InvoicesFreelanceOutstanding ORDER BY OrganizationID </code></pre> <p>The data from that might look like this:</p> <pre> OrganizationName OrganizationID ReceivableStatus InvoiceFee ----------------------------------------------------------------------------- Company A 139 60-90 days 672.00 Company A 139 60-90 days 1800.00 Company A 139 over 90 days 1440.00 Company B 264 Current 3559.38 Company B 264 60-90 days 3785.50 Company C 271 60-90 days 446.25 Company C 271 over 90 days 637.50 Company C 271 over 90 days 1126.25 </pre> <p>What I want to eventually display is something like this (for the data above):</p> <pre> Company Current 30-60 days 60-90 days over 90 days Total ----------------------------------------------------------------------------- Company A 0 0 2472.00 0 2472.00 Company B 3559.38 0 3785.50 0 7344.88 Company C 0 0 446.25 1763.75 2210.00 </pre> <p>My SQL-fu is not enough to get me past this:</p> <pre><code>SELECT MAX(OrganizationName) as OrganizationName, OrganizationID, ReceivableStatus, SUM(InvoiceFee) as TotalDue FROM v_InvoicesFreelanceOutstanding GROUP BY OrganizationID, ReceivableStatus </code></pre> <p>Which shows something like this (again, from the data above):</p> <pre> OrganizationName OrganizationID ReceivableStatus TotalDue ----------------------------------------------------------------------------- Company A 139 60-90 days 2472.00 Company A 139 over 90 days 1440.00 Company B 264 Current 3559.38 Company B 264 60-90 days 3785.50 Company C 271 60-90 days 446.25 Company C 271 over 90 days 1763.75 </pre> <p>What then? Any help would be appreciated.</p> <p>Note that the statuses shown in the 2nd table (<code>Current</code>, <code>30-60 days</code>, <code>60-90 days</code>, <code>over 90 days</code>) are the only ones I'm expecting to come up under <code>ReceivableStatus</code>.</p> <p><strong>EDIT</strong>: Sorry for not including this. I am aware of <code>PIVOT</code> but I couldn't get it to do what I want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload