表
字段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 字段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怎样实现
*
from
tb t
where
not exists(select 1 from tb where 字段1=t.字段1 and 字段2<t.字段1)
select
*
from
tb t
where
not exists(select 1 from tb where 字段1=t.字段1 and 字段2<t.字段2)
select
*
from
tb t
where
字段2=(select min(字段2) from tb where 字段1=t.字段1)
select distinct(字段1) from 表名
*
from
tb t
where
not exists(select 1 from tb where 字段1=t.字段1 and 字段2<t.字段1)