这是我的数据库表:遍历行和计数基于表名
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'然后这是你应该采取的方法。 –