Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can i use Lead function with Group by function

705548Aug 31 2009 — edited Sep 6 2009
I could use this query and get right ouput since i define product id =2000
select product_id, order_date,
lead (order_date,1) over (ORDER BY order_date) AS next_order_date
from orders
where product_id = 2000;

But can i run this query by Group by Function

for example

select product_id, order_date,
lead (order_date,1) over (ORDER BY order_date) AS next_order_date
from orders
group by product_id ;

since data would be like and i need
Product_id order Date
2000 1-jan-09
2000 21-jan-09
3000 13-jan-09
3000 15-jan-09
4000 18-jan-09
4000 19-jan-09

output would be like for eg
Product_id order Date Next_date
2000 1-jan-09 21-jan-09
3000 13-jan-09 15-jan-09
4000 18-jan-09 19-jan-09
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2009
Added on Aug 31 2009
13 comments
2,130 views