• lead函数


    1.

    select  name ,process_operation_name, track_in_time , receiver , track_in_quantity,track_out_time , passer,track_out_quantity , 
           processflow_name,
           processflow_version,
           product_spec_name 
          from (            
           select  distinct timekey,
           name, 
           product_quantity as track_in_quantity , 
           last_event_time as track_in_time, 
           last_event_name as Track_in, 
           last_event_user as receiver,
           lead(last_event_name) over (partition by name,process_operation_name ORDER BY timekey) track_out,
           lead(last_event_time) over (partition by name,process_operation_name ORDER BY timekey) track_out_time,
           lead(last_event_user) over (partition by name,process_operation_name ORDER BY timekey) passer,
           lead(product_quantity) over (partition by name,process_operation_name ORDER BY timekey) track_out_quantity,
        process_operation_name,
           processflow_name,
           processflow_version,
           product_spec_name 
           from job_lot_history 
               where last_event_name = 'TrackIn' 
                   or last_event_name = 'TrackOut'
                   or last_event_name = 'CancelTrackIn') a where a.Track_in = 'TrackIn' and a.track_in_time != track_out_time
                   and name =@lotname ;

    例子

    1.Lot 的TrackIn ,TrackOut ,CancelTrackIn事件

    SELECT 
        name,
        timekey,
        process_operation_name,
        processflow_name,
        processflow_version,
        product_spec_name,
        last_event_name,
        last_event_time
    FROM
        job_lot_history
    WHERE
        (last_event_name = 'TrackIn'
            OR last_event_name = 'TrackOut'
            OR last_event_name = 'CancelTrackIn')
            AND name = 'GGLA598190409019';

     2.将每一行和下一行的数据合并。

    SELECT 
        name,
        timekey,
        process_operation_name,
        processflow_name,
        processflow_version,
        product_spec_name,
        last_event_name as track_in,
        last_event_time as track_out,
        last_event_user as receiver,
        lead(last_event_name) over (partition by name,process_operation_name ORDER BY timekey) track_out,
        lead(last_event_time) over (partition by name,process_operation_name ORDER BY timekey) track_out_time,
       	lead(last_event_user) over (partition by name,process_operation_name ORDER BY timekey) passer
    FROM
        job_lot_history
    WHERE
        (last_event_name = 'TrackIn'
            OR last_event_name = 'TrackOut'
            OR last_event_name = 'CancelTrackIn')
            AND name = 'GGLA598190409019';
    

      

    3.筛选数据

    select  name ,process_operation_name, track_in_time , receiver , track_in_quantity,track_out_time , passer,track_out_quantity , 
           processflow_name,
           processflow_version,
           product_spec_name 
          from (            
           select  distinct timekey,
           name, 
           product_quantity as track_in_quantity , 
           last_event_time as track_in_time, 
           last_event_name as Track_in, 
           last_event_user as receiver,
           lead(last_event_name) over (partition by name,process_operation_name ORDER BY timekey) track_out,
           lead(last_event_time) over (partition by name,process_operation_name ORDER BY timekey) track_out_time,
           lead(last_event_user) over (partition by name,process_operation_name ORDER BY timekey) passer,
           lead(product_quantity) over (partition by name,process_operation_name ORDER BY timekey) track_out_quantity,
        process_operation_name,
           processflow_name,
           processflow_version,
           product_spec_name 
           from job_lot_history 
               where last_event_name = 'TrackIn' 
                   or last_event_name = 'TrackOut'
                   or last_event_name = 'CancelTrackIn') a where a.Track_in = 'TrackIn' and a.track_in_time != track_out_time
                   and name ='GGLA598190409019' ;

    但愿人长久 千里共婵娟
  • 相关阅读:
    我叫mt3.0更新公告
    gcc 编译器常用的命令行参数一览
    C++两个类相互引用错误留影
    C++中的声明与定义
    C++ 杂记
    C++中两个类相互包含引用的相关问题
    Ogre 中使用OIS的两种模式
    Ogre 渲染队列(二)
    Ogre 渲染队列(一)
    Ogre 场景管理器
  • 原文地址:https://www.cnblogs.com/hellcats/p/10729267.html
Copyright © 2020-2023  润新知