[英]want to use group by clause and sum aggregator together
SELECT
state_name AS State_Names,
totaloccupancy AS Total_OccupiedProperties,
totalproperty AS Total_Properties,
CAST(ROUND(totaloccupancy * 100.0 / totalproperty, 1) AS REAL) AS Occupancy_Percentage
FROM
OCCUPANCYPERCENTAGE
輸出:
State_Names Total_OccupiedProperties Total_Properties Occupancy_Percentage
Florida 2 2 100
Florida 1 2 50
Florida 13 16 81.3
Florida 40 51 78.4
Georgia 2 2 100
Georgia 49 54 90.7
Georgia 4 4 100
Georgia 1 1 100
Georgia 1 1 100
Georgia 1 1 100
Georgia 17 17 100
Georgia 7 7 100
Georgia 6 7 85.7
Georgia 15 19 78.9
Georgia 8 9 88.9
Georgia 33 34 97.1
Georgia 9 9 100
Georgia 2 2 100
Georgia 14 18 77.8
Georgia 2 2 100
Georgia 10 12 83.3
Georgia 1 2 50
Georgia 1 1 100
Georgia 9 10 90
Georgia 1 3 33.3
Georgia 2 2 100
Georgia 32 36 88.9
Georgia 1 1 100
Georgia 6 6 100
Georgia 1 1 100
Georgia 87 99 87.9
Georgia 4 6 66.7
Georgia 2 3 66.7
Georgia 1 1 100
Georgia 9 12 75
Georgia 1 1 100
Georgia 4 4 100
Georgia 6 6 100
Georgia 2 3 66.7
Georgia 7 7 100
Georgia 1 1 100
Georgia 2 2 100
Georgia 6 7 85.7
Georgia 46 54 85.2
Georgia 1 1 100
Georgia 1 1 100
Georgia 1 2 50
Georgia 5 6 83.3
Georgia 68 84 81
Georgia 2 2 100
Georgia 3 3 100
Georgia 15 18 83.3
Georgia 7 7 100
Georgia 1 1 100
現在我想按州分組以獲取總占用財產、總財產和總占用百分比,但出現錯誤
消息 8120,第 16 層,狀態 1,第 36 行
列 'OCCUPENCYPERCENTAGE.totaloccupancy' 在選擇列表中無效,因為它不包含在聚合函數或 GROUP BY 子句中。
請幫助
CAST(ROUND(totaloccupancy * 100.0 / totalproperty, 1) AS FLOAT) AS Occupancy_Percentage
嘗試 CAST as FLOAT
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.