Solved

LAG OVER - not returning expected results when without a WHERE

Posted on 2011-03-04
3
405 Views
Last Modified: 2012-06-21
I have this statement which returns expected results for a single email:

SELECT email, ordered_date,
                  LAG(ordered_date,1) OVER (ORDER BY ordered_date) prev_order_date
                  FROM APPS.XXOC_DISC_SALES_MASTER_MV
                  WHERE EMAIL = 'TEDNUGENT@SNET.NET'
                  GROUP BY email, ordered_date
                  order by email, ordered_date

Returns  

But when I remove the WHERE clause and run for all, the lag does not group as expected.

Any ideas?   RESULTSET
0
Comment
Question by:globalwm2
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 125 total points
ID: 35038924
My guess is when you remove the where clause it is doing what it is supposed to do.

Are you wanting to generate the LAG based on email over the entire report?

if so, add a partition:
...
OVER (PARTITION by EMAIL ORDER BY ordered_date)
...
0
 

Author Closing Comment

by:globalwm2
ID: 35038967
Exactly - that was what I needed:

LAG(q1.ordered_date,1) OVER (PARTITION by EMAIL ORDER BY q1.ordered_date) prev_order_date
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35038999
Glad to help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now