关于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 *
from
(
select tb1.*,row_number() over(partition by miwoid order by id) rn
from tb1
)
where rn = 1
group by t1.miwoid) t1
where t1.miwoid = t.miwoid
and t1.createtime = t.createtime)