截断计算列的结果
Truncate results from a calculated column
我正在尝试从计算列的结果中截断或舍入百分比。
select DISTINCT woo.si_number, woo.bill_name, max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price ) as total,
truncate (max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price ) - sum (DISTINCT stk.unit_cost)) / (max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price )) as percentage
from wo_operation woo join wo_bom wob on wob.woo_auto_key = woo.woo_auto_key
join stock stk on stk.pnm_auto_key = wob.pnm_auto_key
join wo_task wot on wot.woo_auto_key = woo.woo_auto_key
join wo_task_skills wts on wts.wot_auto_key = wot.wot_auto_key
where stk.historical_flag = 'F' and
woo.si_number = 'WB6222'
group by woo.si_number, woo.bill_name
order by woo.si_number
结果有很多小数位,只需要2位。
B6222 Company Name 1711.63 0.4693829858088488750489299673410725448841
杰夫
这是你的表情:
truncate (
max (wts.est_hours) * 70.00
+ sum(DISTINCT wob.unit_price)
- sum(DISTINCT stk.unit_cost)
) / (
max (wts.est_hours) * 70.00
+ sum(DISTINCT wob.unit_price)
) as percentage
您(似乎)希望围绕整个计算进行截断,而不是仅针对分子进行截断。所以:
trunc (
(
max (wts.est_hours) *70.00
+ sum(DISTINCT wob.unit_price)
- sum(DISTINCT stk.unit_cost)
) / (
max (wts.est_hours) *70.00
+ sum(DISTINCT wob.unit_price)
),
2
) as percentage
备注:
truncate()
与 Oracle 无关。
trunc()
不是舍入函数:它只是删除额外的数字。如果要四舍五入...请改用 round()
。
sum(distinct ...)
是一个非常原始的东西;仅从您的问题中无法判断这是否真的是您想要的...我可能只是建议您不要使用它,除非您真的知道为什么要这样做。
当存在 group by
子句时 select distinct
是不必要的
我正在尝试从计算列的结果中截断或舍入百分比。
select DISTINCT woo.si_number, woo.bill_name, max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price ) as total,
truncate (max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price ) - sum (DISTINCT stk.unit_cost)) / (max (wts.est_hours) *70.00 + sum (DISTINCT wob.unit_price )) as percentage
from wo_operation woo join wo_bom wob on wob.woo_auto_key = woo.woo_auto_key
join stock stk on stk.pnm_auto_key = wob.pnm_auto_key
join wo_task wot on wot.woo_auto_key = woo.woo_auto_key
join wo_task_skills wts on wts.wot_auto_key = wot.wot_auto_key
where stk.historical_flag = 'F' and
woo.si_number = 'WB6222'
group by woo.si_number, woo.bill_name
order by woo.si_number
结果有很多小数位,只需要2位。
B6222 Company Name 1711.63 0.4693829858088488750489299673410725448841
杰夫
这是你的表情:
truncate (
max (wts.est_hours) * 70.00
+ sum(DISTINCT wob.unit_price)
- sum(DISTINCT stk.unit_cost)
) / (
max (wts.est_hours) * 70.00
+ sum(DISTINCT wob.unit_price)
) as percentage
您(似乎)希望围绕整个计算进行截断,而不是仅针对分子进行截断。所以:
trunc (
(
max (wts.est_hours) *70.00
+ sum(DISTINCT wob.unit_price)
- sum(DISTINCT stk.unit_cost)
) / (
max (wts.est_hours) *70.00
+ sum(DISTINCT wob.unit_price)
),
2
) as percentage
备注:
truncate()
与 Oracle 无关。trunc()
不是舍入函数:它只是删除额外的数字。如果要四舍五入...请改用round()
。sum(distinct ...)
是一个非常原始的东西;仅从您的问题中无法判断这是否真的是您想要的...我可能只是建议您不要使用它,除非您真的知道为什么要这样做。
当存在 select distinct
是不必要的
group by
子句时