我有以下的sql語句,它的工作很好,在一定程度上,如果可能的話,希望使它更好,並且總計得到所有在最後一行的選擇。我也嘗試在一個語句中創建WHERE,但無法返回我在下面完成的命令。MariaDB中的多重選擇語句MySQL
感謝&問候
SELECT
coalesce(account, ' ') AS Account,
sum(gl.credit - gl.debit) AS Balances
FROM `tabGL Entry` AS gl
WHERE account LIKE 'INC%'
GROUP BY account WITH ROLLUP
UNION ALL
SELECT
coalesce(account, ' ') AS Account,
sum(gl.debit - gl.credit) AS Balances
FROM `tabGL Entry` AS gl
WHERE account LIKE 'DCOI%'
GROUP BY account WITH ROLLUP
UNION ALL
SELECT
coalesce(account, ' ') AS Account,
sum(gl.debit - gl.credit) AS Balances
FROM `tabGL Entry` AS gl
WHERE account LIKE 'DMC%'
GROUP BY account WITH ROLLUP
UNION ALL
SELECT
coalesce(account, ' ') AS Account,
sum(gl.debit - gl.credit) AS Balances
FROM `tabGL Entry` AS gl
WHERE account LIKE 'INFC%'
GROUP BY account WITH ROLLUP
UNION ALL
SELECT
coalesce(account, ' ') AS Account,
sum(gl.debit - gl.credit) AS Balances
FROM `tabGL Entry` AS gl
WHERE account LIKE 'IDEX%'
GROUP BY account WITH ROLLUP
爲了澄清結果所需
Inc item 1 ---- 100
Inc item 2 ---- 100
Inc Total ---- 200
DCOI item 1 ---- 100
DCOI item 2 ---- 100
DCOI Total ---- 200
DMC item 1 ---- 100
DMC item 21 ---- 100
DMC Total ---- 200
Total Inc-(DCOI+DMC+INFC+IDEX)
嘗試重新組織數據,以便您可以使用'='而不是'LIKE' – Strawberry
'按賬號LIKE'INC%'排序ñ1時......當帳戶LIKE'IDEX%'然後5結束' – jarlh