济南哪里有做网站的,c2c电子商务网站用到的技术,做网站百度关键排名,重庆那家做网站做得好背景#xff1a; 工作中遇到这样一个业务场景#xff1a;系统中记录订单提报和订单审核通过两个时间点某业务状态#xff0c;开发做标记时一个订单产生了两条记录#xff0c;即提报时记录状态1字段#xff0c;状态2字段为空#xff1b;审核通过时产生新纪录记录状态2字段…背景 工作中遇到这样一个业务场景系统中记录订单提报和订单审核通过两个时间点某业务状态开发做标记时一个订单产生了两条记录即提报时记录状态1字段状态2字段为空审核通过时产生新纪录记录状态2字段状态1字段为空。分析其实想要的是一个订单对应一条记录订单对应的状态1字段和状态2字段。 思路 使用last_value窗口函数可以实现获取某字段当前行的同组中非空值的最后一个使用COALESCE函数判断字段是否为空为空则使用last_value计算出的结果否则使用字段本身值。最后使用分组方法保留每组一条记录。
select order_id,status_submit,status_audit
from(
selectorder_id,coalesce(status_submit, last_value(status_submit) over (partition by order_id order by status_submitrows between unbounded preceding and unbounded following)) as status_submit,coalesce(status_audit, last_value(status_audit) over (partition by order_id order by status_audit rows between unbounded preceding and unbounded following)) as status_audit
fromdbname.tableName
)t
group by order_id,status_submit,status_audit