关于sql语句
我想查出第一,三条数据,也就是每个miwiID 相同的最早创建(createtime)的那条数据,sql该怎么写,求教?
------解决方案--------------------SELECT *
FROM table t
WHERE NOT EXISTS
(SELECT 'x'
FROM table t2
WHERE t.miwoid = t2.miwoid AND t2.createtime< t.createtime)
------解决方案--------------------SELECT *
FROM table t
WHERE miwoid in (select min(createtime) from table a group by miwoid )
------解决方案--------------------select miwoid,min(createtime) from table a group by miwoid
---哎呀,一不小心又写错了。
------解决方案--------------------
select *
from
(
select tb1.*,row_number() over(partition by miwoid order by id) rn
from tb1
)
where rn = 1
------解决方案--------------------select *
from table t exists (select 0
from (select t1.miwoid,
min(t1.createtime) createtime
from table t1
group by t1.miwoid) t1
where t1.miwoid = t.miwoid
and t1.createtime = t.createtime)
------解决方案--------------------select *
from table t where exists (select 0
from (select t1.miwoid,
min(t1.createtime) createtime
from table t1