這是我的數據庫表:遍歷行和計數基於表名
Status
------
Active
Active
Inactive
Removed
Removed
我想要的輸出:
Status | Total | Percent
-------------------------------
Active | 2 | 33.33
Inactive | 1 | 16.66
Removed | 3 | 50
Total | 6 | 100
我已經嘗試:
SELECT
OrderStatus AS Status,
COUNT(OrderStatus) AS Total,
ROUND(((COUNT(OrderStatus) * 100)/COUNT(*)),2) AS Percent
FROM
myTable
對於顯而易見的原因,我的查詢不工作,任何幫助讚賞!
如果接入載體衍生的表,如'SELECT * FROM(SELECT字段從表,其中1 = 2)derivedTable'然後這是你應該採取的方法。 –