SQL语言查询日期最晚的某些条记录

SQL语言查询日期最晚的某些条记录,第1张

正确答案:

select 表.*

from 表,(select 员工id,max(更改时间) 更改时间 from 表 group by 员工id) x

where 表.更改时间=x.更改时间 and 表.员工id=x.员工id

select top 1 *

from (select *

from (select distinct a.ol_id OL_id,

a.ol_nbr购物车ID,

mm.receive_date 消息落地表时间,

a.so_date 购物车抽取时间,

bb.create_date 产品服务定单创建时间,

aa.create_date 资源变更单创建时间,

oo.create_date 流程启动时间,

k.receive_date 报竣时间,

cc.flow_id

from his_wf_event_od mm

join his_srv_tache_order mf

on mf.flow_id = mm.flow_id

join his_srv_crm_tache_order a

on a.to_id = mf.to_id

join his_SRV_B2O_BUSI_ORDER b

on a.to_id = b.to_id

join his_SRV_B2O_BUSI_ORDER_2_PSO bb

on b.action_id = bb.action_id

join his_srv_pso_2_ro aa

on aa.pso_id = bb.pso_id

join his_srv_res_order c

on c.ro_id = aa.ro_id

join his_srv_ro_flow cc

on cc.ro_id = c.ro_id

join his_wf_event_finish k

on cc.flow_id = k.flow_id

join his_srv_ro_event oo

on oo.ro_id = cc.ro_id

where a.ol_id in (250075955915)))

order by oo.create_date desc

SELECT * FROM `tbl` WHERE id IN (

SELECT MAX(id) FROM `tbl`

WHERE createdat BETWEEN ADDDATE(DATE_FORMAT(NOW() ,"%Y-%m-%d"), INTERVAL -6 DAY) AND DATE_FORMAT(NOW(),'%Y-%m-%d')

GROUP BY DATE_FORMAT(createdat,'%Y-%m-%d')

)

前提你的表要有自增主键


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6743269.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-27
下一篇 2023-03-27

发表评论

登录后才能评论

评论列表(0条)

保存