表A
AssessedValueCO AssessedValueUP AssessedValueDW
1.116 2.233 2.239
2.997 2.849 3.496
2.005 3.581 5.692
3.473 5.026 1.619
6.946 4.149 1.616
6.633 3.346 5.832
5.302 3.224 4.05
6.327 6.055 3.368
4.205 4.504 3.368
9.446 1.298 3.333
7.127 0.883 3.923
14.076 0.646 2.323
1.298 5.31 4.037
0.883 2.498 4.675
0.646 5.31 3.855在MS-SQL中如何实现,从表A得出以下结果,谢谢!!
AssessedValueFinal
2.239
3.496
5.692
5.026
6.946
6.633
5.302
6.327
4.504
9.446
7.127
14.076
5.31
4.675
5.31

解决方案 »

  1.   

    http://blog.csdn.net/wufeng4552/archive/2009/10/16/4681510.aspx
      

  2.   

    if object_id('[tb]') is not null drop table [tb]
    create table [tb]([AssessedValueCO] numeric(5,3),[AssessedValueUP] numeric(4,3),[AssessedValueDW] numeric(4,3))
    insert [tb]
    select 1.116,2.233,2.239 union all
    select 2.997,2.849,3.496 union all
    select 2.005,3.581,5.692 union all
    select 3.473,5.026,1.619 union all
    select 6.946,4.149,1.616 union all
    select 6.633,3.346,5.832 union all
    select 5.302,3.224,4.05 union all
    select 6.327,6.055,3.368 union all
    select 4.205,4.504,3.368 union all
    select 9.446,1.298,3.333 union all
    select 7.127,0.883,3.923 union all
    select 14.076,0.646,2.323 union all
    select 1.298,5.31,4.037 union all
    select 0.883,2.498,4.675 union all
    select 0.646,5.31,3.855select  
    case when
    (case when [AssessedValueCO] >= [AssessedValueUP] then [AssessedValueCO] else [AssessedValueUP] end) >=
    [AssessedValueDW] then 
    (case when [AssessedValueCO] >= [AssessedValueUP] then [AssessedValueCO] else [AssessedValueUP] end)
    else [AssessedValueDW] end as AssessedValueFinal
    from [tb]--------------------------------
    2.239
    3.496
    5.692
    5.026
    6.946
    6.633
    5.302
    6.327
    4.504
    9.446
    7.127
    14.076
    5.310
    4.675
    5.310
      

  3.   

    sql2005直接XML就可以了
    sql2000,就union all 合并下不过就3列的话case when也可以搞了
      

  4.   

    select max(value) from (
    select value=AssessedValueCO,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW) from A
    select AssessedValueUP,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW)  from A
    select AssessedValueDW,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW) from A
    )
    group by flag
      

  5.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(我是小F,向高手学习)
    -- Date    :2010-01-21 14:38:59
    -- Version:
    --      Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
    -- Nov 24 2008 13:01:59 
    -- Copyright (c) 1988-2005 Microsoft Corporation
    -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([AssessedValueCO] numeric(5,3),[AssessedValueUP] numeric(4,3),[AssessedValueDW] numeric(4,3))
    insert [tb]
    select 1.116,2.233,2.239 union all
    select 2.997,2.849,3.496 union all
    select 2.005,3.581,5.692 union all
    select 3.473,5.026,1.619 union all
    select 6.946,4.149,1.616 union all
    select 6.633,3.346,5.832 union all
    select 5.302,3.224,4.05 union all
    select 6.327,6.055,3.368 union all
    select 4.205,4.504,3.368 union all
    select 9.446,1.298,3.333 union all
    select 7.127,0.883,3.923 union all
    select 14.076,0.646,2.323 union all
    select 1.298,5.31,4.037 union all
    select 0.883,2.498,4.675 union all
    select 0.646,5.31,3.855
    --------------开始查询--------------------------
    select
     AssessedValue=
    (
    select 
      max(AssessedValueCO)
    from
      (
       select AssessedValueCO 
       union all
       select AssessedValueUP 
       union all
       select AssessedValueDW
       )t
    )
    from
       tb t
    ----------------结果----------------------------
    /* AssessedValue
    ---------------------------------------
    2.239
    3.496
    5.692
    5.026
    6.946
    6.633
    5.302
    6.327
    4.504
    9.446
    7.127
    14.076
    5.310
    4.675
    5.310(15 行受影响)*/
      

  6.   


    select max(value) from (
    select value=AssessedValueCO,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW) from A
    select AssessedValueUP,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW)  from A
    select AssessedValueDW,
      flag=rtirm(AssessedValueCO)+rtirm(AssessedValueUP)+rtirm(AssessedValueDW) from A
    )g
    group by flag
      

  7.   

    select iif(AssessedValueCO>AssessedValueUP,
    iif(AssessedValueCO>AssessedValueDW,AssessedValueCO,AssessedValueDW),
    iif(AssessedValueUP>AssessedValueDW,AssessedValueUP,AssessedValueDW)
    )
    from a