Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL how to create subtotal using JOIN
    primarykey
    data
    text
    <p>I want to make a query similar to this:</p> <pre><code>Cash x Inventory x TOTAL CURRENT ASSET x PPE x TOTAL ASSET x LIST OF LIABILTIES X LIST OF OWNER'S EQUITY X TOTAL LIABILITIES AND OWNER'S EQUITY X </code></pre> <p>X= amount</p> <p>I've managed to get the subtotals and totals using UNION ALL but it gets shown at the very bottom instead of in the middle.</p> <p>Is there a way to do it with a recursive JOIN? because all the data is only from one table.</p> <p>This is what I have so far:</p> <pre><code>SQL&gt; SELECT Acctname AS "Account Name", debit, credit 2 FROM chart_of_accounts_ngo_p 3 WHERE acctno BETWEEN 1010 AND 3200 4 UNION ALL 5 SELECT 'TOTAL CURRENT ASSETS', SUM(debit) - SUM(credit), null 6 FROM chart_of_accounts_ngo_p 7 WHERE acctno BETWEEN 1010 AND 1040 8 UNION ALL 9 SELECT 'TOTAL ASSETS', SUM(debit) - SUM(credit), null 10 FROM chart_of_accounts_ngo_p 11 WHERE acctno BETWEEN 1010 AND 1131 12 UNION ALL 13 SELECT 'TOTAL LIABILITIES AND OE', null, SUM(credit) - SUM(debit) 14 FROM chart_of_accounts_ngo_p 15 WHERE acctno BETWEEN 2020 AND 3200; </code></pre> <p>The report will come out like this:</p> <pre><code>ACCOUNT NAME DEBIT CREDIT ------------------------------ ---------- ---------- CASH 6 ACCOUNTS RECEIVABLE 1 ALLOWANCE FOR DOUBTFUL ACCTS 1 INVENTORY 1 SUPPLIES 1 LAND 1 BUILDING 1 ACCUMULATED DEPR BUILDING 1 MACHINERY 1 ACCUMULATED DEPR MACHINERY 1 ACCOUNTS PAYABLE 1 WAGES PAYABLE 2 TAX PAYABLE 2 NOTES PAYABLE 2 COMMON STOCK 1 RETAINED EARNINGS 1 TOTAL CURRENT ASSETS 8 TOTAL ASSETS 9 TOTAL LIABILITIES AND OE 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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