Ich habe eine Abfrage, die wie folgt aussieht:Zeilen in Spalten und gruppieren
SELECT OrganizationName, OrganizationID, ReceivableStatus, InvoiceFee
FROM v_InvoicesFreelanceOutstanding
ORDER BY OrganizationID
Die Daten aus, dass könnte wie folgt aussehen:
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
Was ich will schließlich ist Anzeige so etwas wie dieses (für die Daten oben):
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
My SQL-fu nicht genug ist, mich daran vorbei:
SELECT
MAX(OrganizationName) as OrganizationName,
OrganizationID,
ReceivableStatus,
SUM(InvoiceFee) as TotalDue
FROM v_InvoicesFreelanceOutstanding
GROUP BY OrganizationID, ReceivableStatus
Das zeigt, wie diese etwas (wieder aus den obigen Daten):
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
Was dann? Jede Hilfe wäre willkommen.
Beachten Sie, dass die Zustände in der zweiten Tabelle dargestellt (Current
, 30-60 days
, 60-90 days
, over 90 days
) sind die einzigen, die ich erwarte unter ReceivableStatus
zu kommen.
BEARBEITEN: Sorry für das nicht einschließlich dies. Ich bin mir bewusst, PIVOT
, aber ich konnte es nicht tun, was ich will.
ich klarer sein sollte; Ich bin PIVOT bewusst, ich konnte es einfach nicht machen, was ich brauche. –
Ich bin ein Idiot. Mein erster Weg zum PIVOT ist, was Sie haben, aber ich habe SUM (InvoiceFee) anstelle von SUM (TotalDue) in der PIVOT-Klausel. Bouhoo. Es funktioniert aber. Vielen Dank. –
Wir machen alle Fehler. Wichtig ist, dass wir von ihnen lernen. Ich bin nur froh, dass ich helfen konnte. – Welbog