我需要一份报告,显示每天/每月/每年的单位数百分比,具体取决于日期范围。
我在PostgreSQL中试过这个,但它没有给出我想要的结果。
SELECT "Code"
,"UnitCount"
,"UnitCount"::FLOAT * 100 / (sum("UnitCount") OVER (PARTITION BY user)) AS "Percent1"
,("UnitCount" / (sum("UnitCount")) * 100) AS "Percent1"
FROM (
SELECT "Code"
,Count("ID") AS "UnitCount"
FROM "TableName"
WHERE DATE BETWEEN '20150227'
AND '20150227'
GROUP BY "Code"
) x
使用公式的预期结果: UnitCount / OverAllUnitCount * 100
UnitCount =每个日期范围代码的计数
OverAllUnitCount =所有日期范围代码的计数
查询PostgeSQL和MySQL会做的。 非常感谢! :d