How can I use the lead/lag in this query
I wrote this query that gives me the comparative data based on this week and next week. How is the lead/Lag used in this query. WITH CURRENT_WEEK
AS ( SELECT QPAQ.YEAR YEAR,
QPAQ.SEASON SEASON,
REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
TO_NUMBER (QPAQ.WEEK) WEEK,
MAX (QPAQ.FAILURES) FAILURES
FROM QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
WHERE QPTL.CATEGORY_ID = 7
AND QPAQ.YEAR = QPTL.YEAR
AND QPAQ.SEASON = QPTL.SEASON
AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
GROUP BY QPAQ.YEAR,
QPAQ.SEASON,
REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
TO_NUMBER (QPAQ.WEEK)
ORDER BY REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+')),
LAST_WEEK
AS ( SELECT QPAQ.YEAR YEAR,
QPAQ.SEASON SEASON,
REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
TO_NUMBER (QPAQ.WEEK + 1) WEEK,
MAX (QPAQ.FAILURES) FAILURES
FROM QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
WHERE QPTL.CATEGORY_ID = 7
AND QPAQ.YEAR = QPTL.YEAR
AND QPAQ.SEASON = QPTL.SEASON
AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
GROUP BY QPAQ.YEAR,
QPAQ.SEASON,
REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
TO_NUMBER (QPAQ.WEEK)
ORDER BY REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'))
SELECT CURRENT_WEEK.YEAR,
CURRENT_WEEK.SEASON,
CURRENT_WEEK.ACC_SERIES,
CURRENT_WEEK.WEEK,
CURRENT_WEEK.FAILURES,
(CURRENT_WEEK.FAILURES - LAST_WEEK.FAILURES) FAILURES_COMPARE
FROM LAST_WEEK, CURRENT_WEEK
WHERE CURRENT_WEEK.WEEK = LAST_WEEK.WEEK(+)
ORDER BY CURRENT_WEEK.WEEK;
Output is like this. YEAR SEASON MODEL WEEK FAILURES Failures_COMPARE
1 2011 SUMMER VGP-BMS15 49 10
2 2011 SUMMER VGP-BMS15 50 28 18
3 2011 SUMMER VGP-BMS15 51 30 2
4 2011 SUMMER VGP-BMS15 52 40 10
Edited by: BluShadow January 6, 2012 13:26addition of {noformat}
{noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.
You would dump the subquery LAST_WEEK together. Then replace the calculation of your failure with
current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compare
I guess you might want to think about renaming the subquery as well...
Cheers, APC
Published by: APC on 6 January 2012 13:41
Tags: Database
Similar Questions
-
I bought an iphone 4 on ebay but it's locked, icloud so I am not able to use it, and the previous owner is available to remove the device from their account: How can I use the appliance?
You can not. Try to return the unit and get your money back. There is absolutely no way for you to unlock the device,
-
I use to manage my DSL modem via an ip address. When I enter FF8 I wonder where to save the file. Why and how can I prevent the FF8 to do this?
And now, whenever I'm in an ip address that I wonder if I want to download the file.
This happens when the modem server does not send the file in text/html, but with a different MIME type.
I tried adding index.html in the event that the server can send this file as text/html.
If your DSL modem has a support Web site, then you can try asking it there advice on how to configure the server modem. -
How can I use the speed dial on my Motorola W490?
How can I use the speed dial on my motorola W490? I have followed the instructions on the manual book, but did not work.
The result, I received the screen is "unauthorized."
Pls help. THX.
Desiree-
Can you tell us what steps you took to set your speed dial and use it?
On page 61, you can find information about adding dial numbers to speed up and 62 mentions how you dial. For example if you have saved your Uncle Paul as Dáil speed 3, you simply hold the button 3 to call this contact.
Mark
Support Forums Manager
-
Adobe Flash Player prevents me to display videos because I don't want to share my personal computer storage.
Wholesale! constitutional question here! Can I use the Windows Media player this Adobe pirate intead? How, please? Or any other way to overcome this in-your-face PEST hijacker - Adobe Flash? * E-mail address is removed from the privacy *
Hello
Flash Player and Windows Media Player are not interchangeable.
Like many things on the web, the Flash Player local storage can be put to bad use. This does not necessarily mean the Flash Player without scruples or bad product - it's the sites Web/people who abuse of this (depending on your point of view).
You can configure Flash Player to block local storage on your computer. This does not necessarily all the features of Flash Player - for example with my set of Flash Player to block local storage I can still see videos on YouTube.
The controls for the Flash Player local storage can be found here: *
Start-> Control Panel-> Flash Player (32-bit) (Tab instorage )
There is a good explanation of privacy and local storage of Flash Player here:
I hope this helps.
* You have not stated your version of Windows, so it's Windows 7.
-
How can I use the same graph of façade in several events in a structure of the event?
I want to display my sensorDAQ signals in a graph.but I have more than one event in the case where the structure to acquire the signal and display it in the first round of graph.the is to acquire signals from threshold and its shown in the graphic as a feedback.after the first event is executed, I'll call the second event, where the other signals are acuired and compared with signals from threshold of event 1 my question is how can I use the same control on front panel in more than two events in the structure of the event? Please answer me I am stuck.
Hello
I have attached here an example of doing the same thing using local variables and shift registers. Take a peek inside. Shift register is always a better option than local variables.
Kind regards
Amine31
(Bravo to give good answers, mark it as a solution if your problem is resolved)
-
How can I use the copy of Windows XP from the desktop on the laptop?
loading xp with a different product code
I have a laptop that works under XP. I lost track of the original disc. I also have an office which was under XP but Win 7 is working now. I have the XP installation disc. How can I use the drive of the desktop on the laptop?
I dought you would get away with it. Try kb892130
Or the pc on a xp boot cd, reinstall xp with xp cd.
-
Windpws Mail & Wi - Fi
I just installed a TalkTalk wireless router which seems to have installed correctly. However when I try to send and receive e-mail using Windows Mail, she wants to use a made up connection. How can I use the wireless connection? Thank you very much, Dianthus MJ.
Go to tools | Accounts | Mail | Properties | Connection and check or change the connection properties. You will need to remove the account and then add it again, but try first and also check tools | Options | Connections.
Steve
-
How can I use the Media Center to watch video content on my smart TV
Separated from this thread.
How can I use the Media Center to watch live video content on my smart TV with Wifi. I couldn't find the instructions to do with Media Player, which I did not
Separated from this thread.
How can I use the Media Center to watch live video content on my smart TV with Wifi. I couldn't find the instructions to do with Media Player, which I did not
do you mean WiFi Direct or WiDi (wireless display)? If WiDi, you need Intel WiDi software installed on a compatible computer.
What brand of TV and the exact model? If you have Windows Media Center on your computer, you should have Windows Media Player. You can have it disabled in programs, but you can reactivate.
-
How can I use the signature keys in my bweb application works
Hi all
How can I use the signature keys in my web work BlackBerry application, I'm looking for video, guide, documentation, step-by-step flow link
Finally how to properly test it on a Simulator before giving the cod to the words App validation team
Thanks for your time
Hello
Have you seen the guides posted here?
What stage are you having problems with?
Erik Oros
BlackBerry Development Advisor
-
Hello
How can I use the "fnd_user_pkg.updateuser" package to disable users in bulk?
in EBS R12.1.3, oracle 11g.
Please see the request for information of the user
-------------------------------------------------------------------------------------
SELECT
SEPARATE
FU. USER_NAME
FULL_NAME EMPLOYEE_NAME
, TO_DATE (LAST_LOGON_DATE, "dd/mm/rrrr") LAST_LOGON_DATE, end_date, FU.start_date
OF FND_USER FU, PER_ALL_PEOPLE_F PERX
WHERE 1 = 1
AND PERX. PERSON_ID = FU. EMPLOYEE_ID
AND SYSDATE BETWEEN PERX. EFFECTIVE_START_DATE AND PERX. EFFECTIVE_END_DATE
AND PERSON_TYPE_ID! = 1118 - excluded candidates iRec
AND LAST_LOGON_DATE < = TO_DATE (December 31, 2012 ', "dd/mm/rrrr") and end_date is null
ORDER BY TO_DATE (LAST_LOGON_DATE, "dd/mm/rrrr") / / desc
------------------------------------------------------------------------------------
Concerning
Ngoyi
Hello
You need to do the opposite of what the code in the discussion below is:
fnd_user_pkg. UpdateUser - End Date remove users
Kind regards
Bashar
-
How can I use the DC Acrobat Customization Wizard to include an Adobe ID sign in?
How can I use the DC Acrobat Customization Wizard to include an Adobe ID sign in? I want my users to install through our deployment tools without having to enter an email address and password after launching the software for the first time. Thank you.
This feature has always existed. In the Customization Wizard screen, fill in all fields and don't forget to click on "Grant offline Exception." This avoids having users connect to activate the product because the product is activated by the administrator on behalf of all users.
HTH,
Ben
-
How can I use the CC of color under Windows?
How can I use the CC of color under Windows?
Or is it an online color Analyzer?
Hello
You can use CC to color online at the Adobe color CC. It is a great web app.
Sue.
-
How can I use the search option in the pdf file in my mobile? [Android]
How can I use the search option in the pdf file in my mobile?
Yes, the text search is also available on Android Acrobat. After you open a PDF file, look in the top bar of the magnifying glass icon. If the top bar is not visible, tap anywhere on the screen to make it appear again.
Thank you
Acrobat DC team Mobile
-
Hello my name is jose and I would like to know how can I use the adobe CAMERA RAW bridge because the use of bridge and the desire to open a raw image of the camera, I get a message that says: BRIDGE HAND aplicaion NOT ACTIVE. BRIDGE REQUIRES THAT A PARTICULAR PRODUCT HAS STARTED AT LEAST ONCE THIS FEATURE. I wonder what that means?
I use a 64 - Bit lapto operating system (windows 7).
Thank you
my email is: [email protected] If you send me the answer to my query
You must activate Photoshop.
Mylenium
Maybe you are looking for
-
I've just updated my Firefox version 15.0 browser on my MacBook. I'm really used to having the tabs under the address bar. However, when I Ctrl-click on a blank section of the band to tabs, there no option "Tabs" at the top on the shortcut menu. Any
-
How can I change the phone number on my apple account
I lost my old number that is connected to my apple account and now I am trying to use the keychain, but his request a verification code that is sent to the old number. I was wondering if anyone knows how to go from the old number attached to my accou
-
Satellite M40X-183: Impossible to install photoshop CS2
I have a Satellite M40X-183. I tried to install Photoshop CS2 and it installs everything but the help files and I wait for hours complete the installation, but it is not. Before it took me a long time to set up but once I updated my toshiba software
-
Hello: I need to compare two index table, to see the file please, and if there is no specific line or column changes then indicate any number of line and colunm How can I do in labview Thank you Brice
-
Hi all, I have a question about the maintenance of the internal battery. I've seen other people pointing to battery maintenance positions, but unfortunately it comes to removable batteries. Question is, what is the best way to take care of a battery