gpt4 book ai didi

mysql - SQL:同时使用 SUM 和 CAST

转载 作者:行者123 更新时间:2023-11-29 06:26:51 24 4
gpt4 key购买 nike

下面是一个查询,用于显示评论表中的列,并将子评级平均为主评级。目前平均评论分数约为 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;

关于mysql - SQL:同时使用 SUM 和 CAST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58979189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com