我想将平均值的小数限制为2 ..这是代码:
select P.prodid, P.prodname, Q.score as "Average Score"
from qualitycheck Q
inner join product P
on P.prodid = Q.prodid
where Q.score >= (select ROUND( AVG(score),2) from qualitycheck where score >= 2.0)
group by P.prodid, P.prodname, Q.score
order by 3 ASC;
答案 0 :(得分:0)
对于Oracle,您可以使用TO_CHAR格式化2位小数;
select P.prodid, P.prodname, TO_CHAR(Q.score, '9999999999.99') as "Average Score"
from qualitycheck Q
...rest of query
请注意,格式字符串中需要足够的数字来覆盖要显示的最大整数位数,否则Oracle会将数字格式设置为#####
。
FORMAT
来获取固定数量的小数位;
select P.prodid, P.prodname, FORMAT(Q.score, 2) as "Average Score"
from qualitycheck Q
...rest of query...
请注意,这会将Average Score
转换为字符串以保留小数,即使数字实际上不需要那么多小数,例如'12 .00'。