How can I use lead/lag in this query
I have written this query which gives me the comparative data based on this week and next week. How can I use Lead/Lag 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 10Edited by: BluShadow on 06-Jan-2012 13:26
added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.
You would jettison the entire LAST_WEEK subquery. Then replace your failure calculation with
current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compareI suppose you might want to think about renaming the sub-query as well ....
Cheers, APC
Edited by: APC on Jan 6, 2012 1:41 PM
Similar Messages
-
How can i use SUM aggregate in select query?
HI,
GURUS,
How can i use SUM function in Select Query and i want to store that value into itab.
for ex:
TABLES: vbap.
types: begin of ty_vbap,
incluse type vbap,
sum type string,
end of ty_vbap.
data: i_vbap type TABLE OF ty_vbap,
w_vbap type ty_vbap.
SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
(or)
SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
loop at i_vbap into w_vbap
" which variable have to use to display summed value.
endloop.
if above code is not understandable pleas give ome sample code on above query.
Thank u,
shabeer ahmed.Hi,
Check this sample code.
TABLES SBOOK.
DATA: COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
INTO (CONNID, COUNT, SUM, AVG)
FROM SBOOK
WHERE
CARRID = 'LH ' AND
FLDATE = '19950228'
GROUP BY CONNID.
WRITE: / CONNID, COUNT, SUM, AVG.
ENDSELECT.
Regards,
Sravanthi -
How can I use the Rownum/Customized SQL query in a Mapping?
Hi,
* I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
* How can I use an Dual table in OWB mapping?
* Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
Thanks in Advance
KishanHi Niels,
As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
Hope this helps...
regards,
Stewart -
How can i use param in my select query ( see code)
Hi ,
I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
I think the limit of args is only till the end of main and my select query is in a method called Load() .
How can i use the param in my select query .
public static void main(String[] args){
name = args[0];
class= args[1];
new Load();
}//end of main
public Load()
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
statement = connection.createStatement();
//First Query : pin and ticket number
ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+ "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
}// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
Edited by: 1sai on Sep 24, 2008 7:35 AMMight I suggest you change the structure of your program to the following:
public class Load {
private Connection conn;
private PreparedStatement statement;
public Load(String sql) {
init(sql);
protected void init(String sql) throws Exception {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
statement = conn.prepareStatement(sql);
public ResultSet execute(String p1, String p2) throws Exception {
statement.setString(1, p1);
statement.setString(2, p2);
return statement.executeQuery();
public void close() throws Exception {
if (statement != null)
statement.close();
statement = null;
if (conn != null)
conn.close();
conn = null;
public static void main(String[] args) throws Exception {
String sql = args[0];
String param1 = args[1];
String param2 = args[2];
Load load = new Load(sql);
ResultSet rs = load.execute(param1, param2);
while (rs.next())
System.out.println(rs.get(0));
rs.close();
load.close();
}This allows you to use the same "Load" object for multiple queries with different parameters.
I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
Hope this helps,
David -
How can I use a class like this?
public class Test<N, T extends Test<N, T>> {
public static void main(String[] args) {
Test<String, Test<String, Test>> test = null; //compile failed...
}I could suggest the following example:public class Test<N, T extends Test<N, T>> {
public void op(T t){
System.out.println("T: " + t.getClass().getName());
public static void main(String[] args) {
SubTest<String> subTest = new SubTest<String>();
subTest.op(subTest);
class SubTest<N> extends Test<N, SubTest<N>>{
}The problem is that T parameter should be a descendant of Test class -
How can I use a variable in webi query filter
I created a webi report using the fiscal year/month(period) field as a filter to show a window of 18 periods. The report works just as requested using a between filter on fiscal period with prompts for both the start and ending periods. Now I'd like to calculate the start period based on what was entered in the prompt for the ending period (e.g. enter 201106 for the TO prompt on the between statement and have the FROM statement filled in as 201001.) I can create variables in the report to display both the user response to the ending period prompt and the calculated starting period, but I cannot figure out how to incorporate that calculated starting date into the FROM side of the between query filter.
Any suggestions?
Thanks,
Doug
Sorry I got my froms and to's mixed up in the first draft. Edited by: Doug Roswold on Mar 4, 2011 6:27 PMLet me understand what you want to do. You don't want to use two prompts, just one, insn't it?
I mean, instead of:
Filter area:
Date between "From prompt" to "To Prompt"
You want something like:.
Filter area:
Date between Variable to "To Prompt"
if I'm not wrong that's not possible to achieve in Webi Query Panel.
Can you modify your universe? The only way to achieve it is modifying your universe, creating your formula in the universe and assigning it to an object, so you can use this new object in your filter area like this:
Date between MyUniverseObject to "To Prompt"
Edited by: PadawanGirl on Mar 4, 2011 8:15 PM -
How can we avoid union all in this query.....
Dear All,
I have a query which has union all.I want a query with the same result without using union all.Can anyone help me?Here is my query.............
SELECT DID,
DM.DISTRICT_DESCRIPTION "DISTRICT_NAME",
MID,
DM.DISTRICT_DESCRIPTION || '(D)' "MANDAL_NAME",
200706,
'SD_OB' "EXP_CAT",
SUM(NVL(AMOUNT,0))-SUM(NVL(AMOUNT1,0)) "AMOUNT" FROM
(SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",NVL(SUM(AMOUNT),0) "AMOUNT", 0 "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE TO_CHAR(AC.CLAIM_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18 '
AND SUBSTR(AC.TRANSACTION_ID,1,3) <> 'CRR'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2),SUBSTR(AC.TRANSACTION_ID,6,2)
union all
SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",0 "AMOUNT" , NVL(SUM(AMOUNT),0) "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE
TO_CHAR(AC.PAY_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2), SUBSTR(AC.TRANSACTION_ID,6,2)), DISTRICT_MASTER DM
WHERE DM.DISTRICT_ID=DID
GROUP BY DID, MID, DM.DISTRICT_DESCRIPTION;
Regards,
Krishnadeep.<I want a query with the same result without using union all>
You can write a pipelined function, which will be about ten times the work. Its best to use the simples tools; why don't you want to use UNION ALL since its probably the best answer? -
How can I add reconciled payments to this query
Select T4.[SlpName] as 'Sales Employee', T0.CardCode, T0.cardname as 'Customer',T0.Docdate as 'Invoice Date', T0.docnum as 'Invoice Number', T0.Taxdate as 'Month Of Service',isnull(T0.U_AIS_DVISFSO,T3.U_AIS_DVISFSO) as 'SO#',T0.NumAtCard as 'PO#', isnull(T0.U_AIS_DVIAdvNm,T3.U_AIS_DVIAdvNm) as 'Advertiser', isnull(T0.U_AIS_DVIOpptyNm,T3.U_AIS_DVIOpptyNm) as 'Campaign',T1.Dscription,-T1.Quantity as 'Impressions',T1.Pricebefdi as 'CPM', Case T0.CurSource When 'C' Then T0.DocCur When 'L' Then T5.MainCurncy When 'S' Then T6.SysCurrncy End As 'Currency DC', Case T0.CurSource When 'C' Then -T1.TotalFrgn When 'L' Then -T1.LineTotal When 'S' Then -T1.TotalSumSy End As 'Total Bef Discount DC', Case T0.CurSource When 'L' Then -T1.[LineVat] When 'C' Then -T1.[LineVatlF] When 'S' Then -T1.[LineVatS] END As 'Vat Tax DC', Case when t1.visorder = 0 Then (Cast(Round((Case T0.CurSource When 'L' Then -T0.DocTotal When 'C' Then -T0.DocTotalFC When 'S' Then -T0.DocTotalSy End), 2) As DECIMAL(18,2))) ELSE 0 END As 'Doc Total DC', Case when t1.visorder = 0 Then (Cast(Round((Case T0.CurSource When 'L' Then -(T0.DocTotal - T0.PaidToDate) When 'C' Then -(T0.DocTotalFC - T0.PaidFC) When 'S' Then -(T0.DocTotalSy - T0.PaidSys) End), 2) As DECIMAL(18,2))) ELSE 0 END As 'Balance after Payment DC', ISNULL(T6.SysCurrncy,'USD') As 'Currency SC', -T1.TotalSumSy As 'Total Bef Discount SC', -T1.[LineVatS] As 'Vat Tax SC', Case when t1.visorder = 0 Then (Cast(Round(-(T0.DocTotalSy), 2) As DECIMAL(18,2))) ELSE 0 END As 'Doc Total SC', Case when t1.visorder = 0 Then (Cast(Round(-(T0.DocTotalSy - T0.PaidSys), 2) As DECIMAL(18,2))) ELSE 0 END As 'Balance after Payment SC', T0.docstatus, 'Credit Memo' AS TransactionType, T0.CurSource,T0.[Comments],T0.[U_InvoiceAdj], T0.[U_DV_AdjustInvReason],T1.[U_DVIInvName], T1.[U_InvoiceAdj], T1.[U_DV_AdjustInvReason] from ORIN T0 left outer join RIN1 T1 on T0.docentry = T1.docentry left outer join RDR1 T2 on T1.Baseentry = T2.docentry and T1.baseline = T2.linenum left outer join ORDR T3 on T2.docentry = T3.docentry left outer join OSLP T4 ON T0.Slpcode= T4.Slpcode Left Join OADM T5 On T0.CurSource = 'L' Left Join OADM T6 On T0.CurSource = 'S' Where T0.cardname Like '%[%0]%' and T0.docstatus ='O'
Hi,
Please check OITR,ITR1 Tables.
Thanks,
Nithi -
How can i LPAD and/or RPAD this query in sql
Hi,
I have a column in a table with value 'True Wheel '. I want the result in the following format:
'True*Wheel*****'
i.e I want to pad '*' on the right as well as at the centre of the two words. Is it possible ?
Please help !SQL>
SQL> with x as (
2 select 'True Wheel' as str from dual union all
3 select 'True Wheel' from dual union all
4 select 'True Wheel' from dual union all
5 select 'True Wheel' from dual union all
6 select 'True Wheel' from dual union all
7 select 'True Wheel' from dual)
8 --
9 select str, rpad(replace(str,' ','*'),15,'*') as mod_str
10 from x;
STR MOD_STR
True Wheel True*Wheel*****
True Wheel True**Wheel****
True Wheel True***Wheel***
True Wheel True****Wheel**
True Wheel True*****Wheel*
True Wheel True******Wheel
6 rows selected.
SQL>
SQL>cheers,
pratz -
we have a Linux fileserver with Samba share and have several users.
The users tend to be in different locations and need to login at different workstations, sometimes the workstation may be WindowsXP and othertimes it is windows7.
How can we use Firefox & Thunderbird in this situation.
I find that Windows7 uses compressed files to store the location information.
when a user logs on to win7 it creates a new account.we have a Linux fileserver with Samba share and have several users.
The users tend to be in different locations and need to login at different workstations, sometimes the workstation may be WindowsXP and othertimes it is windows7.
How can we use Firefox & Thunderbird in this situation.
I find that Windows7 uses compressed files to store the location information.
when a user logs on to win7 it creates a new account. -
Can I use LEAD or LAG with Groups?
Can I use LEAD or LAG with Groups?
I want to compare two records of each group.
Is it possible?
Thanks in advanceXavi wrote:
I have this query:
SELECT a.cod_riesgo_txpk as num_poliza,
a.cod_suplementor_txpk as suplemento,
a.movimiento_nmpk as movimiento,
a.cod_tipo_operacion_txfk as tipo_operacion,
rc.fecha_vcto_cobertura_txd as fecha_vto,
rc.capital_asegurado_nm as capital,
rc.prima_total_nm as prima
FROM REGU_RIESGOS_COBERTURAS rc, REGU_MOVIMIENTOS_POLIZAS a
WHERE rc.cod_cobertura_txpkfk ='005'
AND rc.cod_riesgo_txpkfk = a.cod_riesgo_txpk
AND rc.cod_suplementor_txpkfk = a.cod_suplementor_txpk
AND rc.movimiento_nmpkfk = a.movimiento_nmpk
order by num_poliza, movimiento;
The results:
NUM_POLIZA SUPLEMENTO MOVIMIENTO TIPO_OPERACION FECHA_VTO CAPITAL PRIMA
0640080109141 0640080109141/014 1 02 01/05/2010 15025302,61 3,19
0640180096274 0640180096274/006 1 02 01/05/2006 1652783 1387,8
0640180365194 0640180365194/005 1 02 08/07/2006 150253 294,83
0640180369821 0640180369821/009 1 02 31/12/2006 13460000 28483,08
0640180369821 0640180369821/010 2 02 28/02/2007 13460000 29546,08
0640180384185 0640180384185/010 1 02 30/12/2006 36085241,96 113951,53Can yo see NUM_POLIZA 0640180369821 I have two records, then I want to compare two rows in each grou.What do you mean by compare? What do you want to do?
You can use the PARTITION BY clause if you want the analytic function to work within a specific group. -
how can i use my account without the billing info, as i do not have a credit card. and my shipping and billing info is under US. i'm in singapore. how do i change this?
If you are just visiting Singapore, then leave the account as it is. If you have moved there, then view your account using the iTunes app on a Mac or PC and change the country/region to your current location and address. If you do not have a bank card, you can fund your account using iTunes gift cards if available in Singapore.
-
Dear Support Team,
Every time i tried to logon Icloud its gives me wrong user name or password and at the end it show me error " This Apple ID is valid but is not an ICloud Account" then how can i use one account for same Apple ID and ICloud?
ThanksIt is not possible to create a new iCloud account using a Windows machine. You must create the account using a Mac (10.7.5 or more) or an IOS device (iPhone etc). Once that is done you can sign into and use the account on your Windows machine.
-
How can I use the old Apple TV with new iTunes? It tells me to input a code in iTunes but iTunes no longer has a spot to input this code to allow sync. I can access the iTunes Store fine, just none of my Library
read this
https://discussions.apple.com/message/20429789#20429789 -
My employer is issuing an iPad 4 to me, but has informed me that "...I can expect no privacy" with regard to any information on it. What has me concerned is that my employer has also requested that I use my Persoanl iTunes account to syc and update the iPad. I am concerend with my personal privacey, as I have two other iPads that use this account regualary.
My question is: How can I use iTunes to update etc. the company iPad using iTunes without compromising my personal information?
What I have done is to set up a different sign in (is that called an Apple ID?) within iTunes (I now have two different names I can use to sign in to iTunes). They both still use the same iTunes and my personal apps and information appear to be available to my second sign in name (the second sign in name is what I intend to use for the company iPad). When I sync the company iPad how do/can I keep my persoanl information from being syc'd automatically to the comapany iPad?Hi herbie13!
It sounds like you will still want to link your iPad and computer, but you want to prevent the iPad from syncing information from your computer to your iPad. I have an article here for you that can help tell you how to set this up:
iOS: Syncing with iTunes
http://support.apple.com/kb/ht1386
You will want to follow the steps here to set up the iPad for syncing, but when it comes time to sync, you'll just want to make sure that the boxes for syncing the multitude of items that you can sync remain unchecked so that none of that information gets synced into the iPad.
Another note: your second Apple ID will not be able to access the apps, music, movies, tv shows, etc., that you have purchased under your primary Apple ID. Even though it seems that the secondary Apple ID still has access to those items, that is just because you are viewing your second Apple ID through the iTunes Store section on your computer and you have those items saved locally on your computer. You will need to repurchase and download all of the content that you wish to use again on your second Apple ID, if that is what you wish to solely use on this iPad.
Take care, and thanks for visiting the Apple Support Communities.
-Braden
Maybe you are looking for
-
How to export layer in jpg files ?
Hi everyone, I am trying to develop a plug-in for Ai CS4 in which I need to export all the layers in jpg files. Could any one tell me the API that can help me to do so ? or any suggestion how I can do this. thanks in advance.
-
[SOLVED] kernel-headers & VirtualBox. Still same problems! (
Hi guys, i'm new to this forum, but i didn't found an answer anywhere! I'm trying to install VirtualBox 4.2.10 from terminal on my x86 Oracle Linux. Half year ago, when i tried first, i couldn't resolv the problem and still the same problem today - N
-
my photos appear as ithumb files not as microsoft pictures? is this right?
-
I am currently using the OC4J as a previewver for running reports i would like to deploy them on Oracle 9iAS.When i run the test.pdf the report runs sucessfully but its not able to run any other of my reports though all the necessary configuraions ha
-
SRM /APO study material required
Hi Gurus I am new to SRM and APO. Can someone give me some links, blogs, etc where I can find SRM and APO study material. Please help My email i.d is [email protected] Thumilan