如下表1:
------------------------
编号   变形值1      102       -53      124      -6 
--------------------------
我要取出最大的变形值和改值的编号,最大的变形值就是指绝对值最大的那个不能用abs,因为abs后都是正数了,我需要原始的值(当最大变形值为负的话)这个SQL该如何写???

解决方案 »

  1.   

    select a.编号,a.变形值 from(select 编号,max(abs(变形值)) from 表1) a
      

  2.   

    select 变形值 from table order by asb(变形值) desc
      

  3.   


    select * from users where PKID=(select max(PKID) from users)类比下你自己换列名期待高手更好的方法
      

  4.   

    select 编号,max(abs(变形值)) from 表1这样取 编号是取不出来的
      

  5.   

    3楼 5楼 直接 MAX是没有用的 我是要取绝对值最大 不是正数最大
      

  6.   


    select 编号,变形值 from 表名 where abs(变形值)=(select max(abs(变形值)) from 表明)
      

  7.   

    select 编号,变形值 
    from 表1 
    where abs(变形值) = (
                        select max(abs(变形值)) from 表1 )
      

  8.   

    declare @t table(编号 int,变形值 int)
    insert @t select 1,10
    union all select 2,-5
    union all select 3,12
    union all select 4,-6--方法一
    select *
    from @t
    where abs(变形值)=(select max(abs(变形值)) from @t)--方法二
    select top 1 *
    from @t
    order by abs(变形值) desc/*
    所影响的行数为 4 行)编号          变形值         
    ----------- ----------- 
    3           12(所影响的行数为 1 行)编号          变形值         
    ----------- ----------- 
    3           12(所影响的行数为 1 行)*/
      

  9.   

    哎 各位XD都不看清楚需求乱讲 
     
    还是10楼的XD写的有用
      

  10.   

    sorry
    应该是这样
    select a.编号,a.变形值 from 表1 a,(select 编号 from 表1 where abs(变形值)=(select max(abs(变形值)) from table2)) b where a.编号=b.编号
      

  11.   

    select 编号,变形值 from 表名 where abs(变形值)=(select min(abs(变形值)) from 表明)
    应该是差量最小的一个才对