[英]SQL: Using Both SUM and CAST
下面是一個查詢,用於顯示 Review 表中的列,並將子評分平均為主評分。 目前,平均評論分數將類似於 7.40000000。 有什么辦法可以同時使用 cast 和 sum 嗎? 理想情況下,我想將其轉換為一位小數,這樣它只會顯示 7.4。 我試圖根據我看到的其他答案來編輯我的查詢,但我似乎無法讓它工作。
SELECT Review_ID, Customer_ID, Property, Room, Order_ID,
Date_of_Stay,Customer_Country,
SUM((Rating_Cleanliness+Rating_Comfort+Rating_Location+Rating_Staff+Rating_Value)/5) AS Review_Score
FROM `PCT_Review`
GROUP BY Review_ID;
非常感謝。
我想你可以一起使用它們
SELECT Review_ID,
Customer_ID,
Property,
Room,
Order_ID,
Date_of_Stay,
Customer_Country,cast(SUM((Rating_Cleanliness+Rating_Comfort+Rating_Location+Rating_Staff+Rating_Value)/5) as decimal (10,1))
AS Review_Score
FROM `PCT_Review`
GROUP BY Review_ID,
Customer_ID,
Property,
Room,
Order_ID,
Date_of_Stay,
Customer_Country;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.