字段1        字段2      字段3
AS             0         T/T
AS             1         NULL
AS             2         NULL
AS             3         NULL
YY             0         NULL
DFS            0         HY
SD             0         JJ
SD             1         NULL
SD             2         NULL
SD             3         NULL
SD             4         NULL
SD             5         NULL
...结果
字段1        字段2      字段3
AS             0         T/T
YY             0         NULL
DFS            0         HY
SD             0         JJsql怎样实现

解决方案 »

  1.   

    select
      *
    from
      tb t
    where
      not exists(select 1  from tb where 字段1=t.字段1 and 字段2<t.字段1)
      

  2.   

    select * from tb where 字段2=0
      

  3.   

    ---修改
    select
      *
    from
      tb t
    where
      not exists(select 1  from tb where 字段1=t.字段1 and 字段2<t.字段2)
      

  4.   

    或者
    select
     *
    from
     tb t
    where 
     字段2=(select min(字段2) from tb where 字段1=t.字段1)
      

  5.   

    select * from where 字段2='0'
      

  6.   

    SELECT * FROM TB T WHERE 字段3=(SELECT MAX(字段3) FROM TB WHERE T.字段1=字段1 )
      

  7.   


    select distinct(字段1) from 表名
      

  8.   

    select * from tb where 字段2=0
      

  9.   

    select
      *
    from
      tb t
    where
      not exists(select 1  from tb where 字段1=t.字段1 and 字段2<t.字段1)