tb_a
  id   col1      col2     col3
   1    81        0.5     0.15
   1    57        0.2     0.13
   1    177       0.8     0.25我要得到的结果是
col4 = col1*col2*col3
col4 就是实际的结果
col5 = round(col1*col2*col3,0)
col5是四舍五入的结果。按小数点一位四舍五入tb_b
   id   col1     col2     col3    col4     col5 
   1    81        0.5     0.15    6.075     6
   1    57        0.2     0.83    9.462     10
   1    177       0.8     0.85    120.36    120 

解决方案 »

  1.   

    select *,col4=col1*col2*col3 ,col5=round(col1*col2*col3,0) 
    from tb
      

  2.   

    select *,col4=col1*col2*col3 ,col5=round(col1*col2*col3,0) 
    from tb
      

  3.   

    ------ Test Data: tb_a
    If object_id('tb_a') is not null 
        Drop table tb_a
    Go
    Create table tb_a(id int,col1 int,col2 numeric(12,2),col3 numeric(12,2))
    Go
    Insert into tb_a
    select 1,81,'0.5','0.15' union all
    select 1,57,'0.2','0.83' union all
    select 1,177,'0.8','0.85' 
    Go
    --Start
    Select * ,col4 = col1*col2*col3,col5 =  round(round(col1*col2*col3 ,1),0) from tb_a
    --Result:
    /*
    id          col1        col2           col3           col4                                   col5                                   
    ----------- ----------- -------------- -------------- -------------------------------------- -------------------------------------- 
    1           81          .50            .15            6.0750                                 6.0000
    1           57          .20            .83            9.4620                                 10.0000
    1           177         .80            .85            120.3600                               120.0000(所影响的行数为 3 行)*/
    --End 
      

  4.   

    select *,col4=col1*col2*col3 ,col5=round(col1*col2*col3,0) from tb
      

  5.   

    ---测试数据---
    if object_id('[tb_a]') is not null drop table [tb_a]
    go
    create table [tb_a]([id] int,[col1] int,[col2] numeric(2,1),[col3] numeric(3,2))
    insert [tb_a]
    select 1,81,0.5,0.15 union all
    select 1,57,0.2,0.13 union all
    select 1,177,0.8,0.85
     
    ---查询---
    select *,col4=(col1*col2*col3),col5 = cast((col1*col2*col3) as dec(18,0)) from [tb_a]
    ---结果---
    id          col1        col2 col3  col4                col5                 
    ----------- ----------- ---- ----- ------------------- -------------------- 
    1           81          .5   .15   6.075               6
    1           57          .2   .13   1.482               1
    1           177         .8   .85   120.360             120(所影响的行数为 3 行)