Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 截断计算列的结果_Sql_Oracle_Aggregate Functions - Fatal编程技术网

Sql 截断计算列的结果

Sql 截断计算列的结果,sql,oracle,aggregate-functions,Sql,Oracle,Aggregate Functions,我试图从计算列的结果中截断或四舍五入一个百分比 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

我试图从计算列的结果中截断或四舍五入一个百分比

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
    子句时,不需要选择distinct


此处无需选择DISTINCT,您的GROUP BY不会返回重复的行。
round
计算结果
truncate()
在Oracle中不存在。你确定这就是你正在运行的数据库吗?谢谢,伙计们,Trunc工作了,我真的没有语法来完成所有的括号。由于有多条库存线,必须在某些方面进行区分。