Oracle LAG Function

Source: Internet
Author: User

/* Formatted on 4:51:00 (QP5 v5.149.1003.31008 )*/
SELECT *
FROM (SELECT
A. lot_id,
A. shift_start_timekey,
A. event_name,
A. old_oper_code,
A. oper_code,
'-',
LAG (old_oper_code, 2) OVER (order by lot_id, event_timekey)
Previus_2,
LAG (old_oper_code, 1) OVER (order by lot_id, event_timekey)
Previus_1,
A. old_oper_code previus_0
FROM eds_lot_hist
WHERE a. factory = 'module' -- AND OLD_OPER_CODE = 'r510'
-- AND a. lot_id = '8awx1z0277b1c6'
AND shift_start_timekey = '2017 20120101'
AND a. old_oper_code <> a. oper_code
AND a. event_name IN ('trackout', 'trackoutrework', 'fa ')
Order by lot_id, event_timekey)
WHERE previus_2 IN ('r540', 'r530', 'r550 ', 'r510 ')
AND PREVIOUS_1 = 'r551'
AND PREVIOUS_0 = 'r510 ';

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.