我在SQL下面会返回结果,但我希望价格四舍五入到小数点后6位。
select opt.blo,
opt.premiumcurrency,
case
when opt.structurename is not null then opt.basemarketprice /100
when pct = 1 then opt.basemarketprice /100
when pct = 2 then opt.termmarketprice / opt.notional
when opt.notionalcurrency = opt.premiumcurrency then opt.basemarketprice /100
else opt.termmarketpricepercent /100
end as round(price,6)
from interafce opt
当我在下面添加时,它会给我错误
ORA-00923:找不到FROM关键字
感谢您的帮助。
答案 0 :(得分:2)
case
需要进入round()
。您将该函数与别名混淆:
round(case when opt.structurename is not null then opt.basemarketprice /100
when pct = 1 then opt.basemarketprice /100
when pct = 2 then opt.termmarketprice / opt.notional
when opt.notionalcurrency = opt.premiumcurrency then opt.basemarketprice /100
else opt.termmarketpricepercent /100
end, 6) as roundedPrice
答案 1 :(得分:1)
以圆形(价格,6)结束不起作用。您将列别名为" round(price,6)"
宁愿做一个
select .....
....
when opt.structurename is not null then round(opt.basemarketprice /100,6)
when pct = 1 then round(opt.basemarketprice /100,6)
when pct = 2 then round(opt.termmarketprice / opt.notional,6)
when opt.notionalcurrency = opt.premiumcurrency then round(opt.basemarketprice /100,6)
else round(opt.termmarketpricepercent /100,6)
end as rounded_price