本文介绍了添加$和圆2小数位的SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找格式化由子查询创建的输出,这个子查询产生一个计算的字段,我想格式化为$ XX.XX。



子查询:

 (从汽车中选择平均值(零售)
其中brand ='FORD'或品牌='TOYOTA')作为AVG_BRAND_PRICE_01

我基本上只想添加一个$符号并围绕输出到小数点后两位。

任何帮助或方向都将不胜感激。

我正在使用isql plus oracle 11g

解决方案

您可以试试这个:

 '$'|| ((选择平均(零售)从汽车
where brand ='FORD'或品牌='TOYOTA')作为十进制(4,2))AVG_BRAND_PRICE_01

如果你想要多于$ XX.XX例如$ XXXXXXX.XX那么你将需要设置小数点以上十进制(9,2)



示例SQL小提琴:


I am looking to format an ouput which is created by a sub-query, this sub-query produces a calculated field which i would like to format as $XX.XX.

Sub query:

(select avg(retail) from cars 
where brand = 'FORD' or brand = 'TOYOTA') as AVG_BRAND_PRICE_01

I basically just want to add a $ sign and round the output to two decimal places.

Any help or direction would be much appreciated.

I am using isql plus oracle 11g

解决方案

You could try this:

'$' || Cast((select avg(retail) from cars 
where brand = 'FORD' or brand = 'TOYOTA') as decimal(4,2)) as AVG_BRAND_PRICE_01

If you want more than $XX.XX e.g $XXXXXXX.XX then you will need to set the decimal higher e.g. decimal(9,2)

Example SQL Fiddle: http://www.sqlfiddle.com/#!4/9f684/2/0

这篇关于添加$和圆2小数位的SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 00:34