Query comparison

Hello ,
I would really apreciate if some one can help me with there
expert opinion.
Mentioned below is a query
SELECT
S.ACCT_EVENT_TYPE_CD
,S.CUST_ACCT_EVENT_ID
,S.EVENT_USED_BY_CD
,S.EVENT_SEQUENCE_CD
,S.DW_AS_OF_DT
,S.CUST_ACCT_EVENT_CD
,S.EXT_EVENT_REF_CD
,S.EVENT_START_DT
,S.EVENT_END_DT
,S.AUDIT_USER_ID
,S.AUDIT_UPDT_TS
,S.DW_ACTN_IN
,S.DW_DATA_CHG_TS
,S.DW_LOAD_TS
FROM
IDW_STAGE.CUST_ACCT_EVENT_S S
LEFT OUTER JOIN
(SELECT ACCT_ID,
CUST_ID,
EVNT_USE_BY_CD,
EVNT_SEQ_CD,
MAX(DW_EFF_DT) DW_EFF_DT
FROM IDW_DATA.CUST_ACCT_EVENT_T
GROUP BY 1,2,3,4) T
ON
( T.ACCT_ID=0
AND T.CUST_ID=S.CUST_ACCT_EVENT_ID
AND S.ACCT_EVENT_TYPE_CD='C'
OR
( T.CUST_ID=0
AND T.ACCT_ID=S.CUST_ACCT_EVENT_ID
AND S.ACCT_EVENT_TYPE_CD='A'
AND T.EVNT_USE_BY_CD = S.EVENT_USED_BY_CD
AND T.EVNT_SEQ_CD = S.EVENT_SEQUENCE_CD
WHERE
S.DW_AS_OF_DT > T.DW_EFF_DT
AND
S.DW_ACTN_IN in ('I','U');
Will there be a difference in output in terms of data(not performance) if we modify the above mentioned query as
SELECT
S.ACCT_EVENT_TYPE_CD
,S.CUST_ACCT_EVENT_ID
,S.EVENT_USED_BY_CD
,S.EVENT_SEQUENCE_CD
,S.DW_AS_OF_DT
,S.CUST_ACCT_EVENT_CD
,S.EXT_EVENT_REF_CD
,S.EVENT_START_DT
,S.EVENT_END_DT
,S.AUDIT_USER_ID
,S.AUDIT_UPDT_TS
,S.DW_ACTN_IN
,S.DW_DATA_CHG_TS
,S.DW_LOAD_TS
FROM
idw_stage.CUST_ACCT_EVENT_S S
LEFT OUTER JOIN
(SELECT ACCT_ID,
CUST_ID,
EVNT_USE_BY_CD,
EVNT_SEQ_CD,
MAX(DW_EFF_DT) DW_EFF_DT
FROM idw_data.CUST_ACCT_EVENT_T
GROUP BY 1,2,3,4) T
ON T.ACCT_ID=0
AND T.CUST_ID=S.CUST_ACCT_EVENT_ID
AND S.ACCT_EVENT_TYPE_CD='C'
AND T.EVNT_USE_BY_CD = S.EVENT_USED_BY_CD
AND T.EVNT_SEQ_CD = S.EVENT_SEQUENCE_CD
WHERE
S.DW_AS_OF_DT > COALESCE(T.DW_EFF_DT,date '0001-01-01')
AND
S.DW_ACTN_IN in ('I','U')
UNION
SELECT
S.ACCT_EVENT_TYPE_CD
,S.CUST_ACCT_EVENT_ID
,S.EVENT_USED_BY_CD
,S.EVENT_SEQUENCE_CD
,S.DW_AS_OF_DT
,S.CUST_ACCT_EVENT_CD
,S.EXT_EVENT_REF_CD
,S.EVENT_START_DT
,S.EVENT_END_DT
,S.AUDIT_USER_ID
,S.AUDIT_UPDT_TS
,S.DW_ACTN_IN
,S.DW_DATA_CHG_TS
,S.DW_LOAD_TS
FROM
idw_stage.CUST_ACCT_EVENT_S S
LEFT OUTER JOIN
(SELECT ACCT_ID,
CUST_ID,
EVNT_USE_BY_CD,
EVNT_SEQ_CD,
MAX(DW_EFF_DT) DW_EFF_DT
FROM idw_data.CUST_ACCT_EVENT_T
GROUP BY 1,2,3,4) T
ON T.CUST_ID=0
AND T.ACCT_ID=S.CUST_ACCT_EVENT_ID
AND S.ACCT_EVENT_TYPE_CD='A'
AND T.EVNT_USE_BY_CD = S.EVENT_USED_BY_CD
AND T.EVNT_SEQ_CD = S.EVENT_SEQUENCE_CD
WHERE
S.DW_AS_OF_DT > COALESCE(T.DW_EFF_DT,date '0001-01-01')
AND
S.DW_ACTN_IN in ('I','U')
Thanxs

I think the number oof records will be same.
But would this be sufficient?
SELECT S.ACCT_EVENT_TYPE_CD
      ,S.CUST_ACCT_EVENT_ID
      ,S.EVENT_USED_BY_CD
      ,S.EVENT_SEQUENCE_CD
      ,S.DW_AS_OF_DT
      ,S.CUST_ACCT_EVENT_CD
      ,S.EXT_EVENT_REF_CD
      ,S.EVENT_START_DT
      ,S.EVENT_END_DT
      ,S.AUDIT_USER_ID
      ,S.AUDIT_UPDT_TS
      ,S.DW_ACTN_IN
      ,S.DW_DATA_CHG_TS
      ,S.DW_LOAD_TS
FROM IDW_STAGE.CUST_ACCT_EVENT_S S
LEFT OUTER JOIN
(SELECT ACCT_ID,
        CUST_ID,
        EVNT_USE_BY_CD,
        EVNT_SEQ_CD,
        MAX(DW_EFF_DT) DW_EFF_DT
FROM IDW_DATA.CUST_ACCT_EVENT_T
GROUP BY 1,2,3,4) T
ON
( T.ACCT_ID=0
AND T.CUST_ID=S.CUST_ACCT_EVENT_ID
AND S.ACCT_EVENT_TYPE_CD in ('C', 'A')
AND T.EVNT_USE_BY_CD = S.EVENT_USED_BY_CD
AND T.EVNT_SEQ_CD = S.EVENT_SEQUENCE_CD
WHERE
S.DW_AS_OF_DT > T.DW_EFF_DT
AND
S.DW_ACTN_IN in ('I','U');Illustration on number of records.
SQL> with t as (select '1' a from dual
  2             union
  3             select '2' a from dual
  4             union
  5             select '3' a from dual
  6             union
  7             select '4' a from dual
  8             union
  9             select '5' a from dual
10             union
11             select '6' a from dual
12             union
13             select '4' a from dual)
14  select a from t
15  where t.a = '1'
16  or t.a = '4';
A
1
4
2 rows selected.
SQL> with t as (select '1' a from dual
  2             union
  3             select '2' a from dual
  4             union
  5             select '3' a from dual
  6             union
  7             select '4' a from dual
  8             union
  9             select '5' a from dual
10             union
11             select '6' a from dual
12             union
13             select '4' a from dual)
14  select a from t
15  where t.a = '1'
16  union
17  select a from t
18  where t.a = '4';
A
1
4
2 rows selected.
SQL>Cheers
Sarma.

Similar Messages

  • Query Comparison in DEV, QA and PROD

    Hi,
    Is there any way to compare the queries in DEV, QA and PROD to make sure that all the boxes have all the queries (provided we have followed the system landscape like transporting from DEV to all other two).
    If not (this is happenning most of the time, because users are creating queries directly in PROD), we have to compare each and every query against the particular Data target in all the three environment. 
    We want to have a control in such a way that all queries are only created in DEV by the users and we will transport to QA and PROD. Once after making sync between landscape, we will restrict the access to the users to create directly in PROD.
    Please help urgently.
    Thanks,
    David

    Hi,
    Use S_RS_COMP and S_RS_COMP1 for BEx security and specifically for Query use S_QUERY.
    Cheers,
    Kedar
    Message was edited by: Kedar Patil

  • Physical Query in OBIEE 10g vs OBIEE 11g

    Hi Everyone,
    We're in the middle of an OBIEE 10g to an OBIEE 11.1.1.6.4 upgrade and as part of our assembly testing we were planning on comparing the physical query generated for a report generated in obiee 10g vs the physical query for a report in obiee 11g.
    After a couple reports we noticed that the query structure in 11g is completely different than the query structure in 10g. The reports still generated the same data in 10g vs 11g. So my question is:
    1) is it worth while (or necessary) to do a physical query comparison for an obiee 10g to 11g upgrade? or is validating the front-end report data & drill down/interactions adequate?
    2) what are some general reasons why a query generates differently in obiee 10g vs 11g?

    Pl post details of OS versions, exact database versions (to 4 digits) and init.ora parameters of the 10g and 11g databases. Have statistics been gathered after the upgrade ?
    For posting tuning requests, pl see these threads
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long ...
    Pl see if the SQL Performance Analyzer can help - MOS Doc 562899.1 (TESTING SQL PERFORMANCE IMPACT OF AN ORACLE 9i TO ORACLE DATABASE 10g RELEASE 2 UPGRADE WITH SQL PERFORMANCE ANALYZER)
    HTH
    Srini

  • Greater than or equal to

    Hi everyone. I have what I think is a simple query (see
    below) that pulls date information from a table. As you can see
    from the query, I want it to pull dates for anything greater than
    and equal to today's date and anything less than and equal to a
    date one week from today's date.
    This works, however, CF does not output any events on today's
    date; it begins outputting tomorrow's events. Can someone point me
    in the right direction as how to fix this so dates for today are
    output as well? Thanks!

    For the "up through day" portion, I truncate the time component off of now(), add a day, and then use only the less than comparison. Example:
         <cfset variables.dt1 = dateAdd("d",1,int(now())) />
         <cfset variables.dt2 = dateAdd("d",-8,variables.dt1) />
         <p>dt1 = #variables.dt1# / dt2 = #variables.dt2#</p>
    This results into:
         dt1 = {ts '2013-09-28 00:00:00'} / dt2 = {ts '2013-09-20 00:00:00'}
    Lastly, use the results in your query comparison:
         where
              [someDateField] < <cfqueryparam value="#variables.dt1#" cfsqltype="CF_SQL_DATE" />
              and [someDateField] >= <cfqueryparam value="#variables.dt2#" cfsqltype="CF_SQL_DATE" />
    Also, the cfsqltype of CF_SQL_DATE seems to truncate the time component off the date for you in CF9 & CF10, but I don't like dependencies like that as I've been burned in the past. If you don't mind the risk, you can simplify the logic by removing the int() function from the above.

  • Insertion using objects and update using queries in a single unit of work

    HI All,
    I have a set of objects that i want to insert and then perform some update queries ( direct queries ) on the inserted data in the same transaction. but when i register the objects and execute the update SQL's on the same data in a same unit of work, the update statements are executed first and then the inserts are happening, I've also tried with child unit of work and parent unit of work but the result is the same.
    Can any one suggest a way to do object insertion and sql updates in a single transaction, Thanks in advance
    Regards,
    Sai Krishna

    The UnitOfWork is an abstraction for the physical database query. By default nothing is actually written into the database until the UnitOfWork commits. This means making updates to new objects involves modifying them in-memory and then the updated values will be included in the INSERT during commit.
    If you are having difficulty finding the newly created objects you can enable the query conforming capabilities to have modified and new objects included in query comparisons without requiring them to first be written to the database.
    Doug

  • Comparing two queries with VBA macro

    Hi,
    I have a workbook woth 2 sheets. Every sheet has a BEx query (so 2 queries).
    I need, for every column in the first query, to check if it is present in the second query, to generate a list with the NOT PRESENT values (or simply, marking the not present values).
    I tried with Searching excel functions by column, but every query hs more that 30.000 rows, so it takes a long time.
    I think I have to use an excel macro. I have been lookong for in the forum but my doubt is that I have to execute when the two queries has been refreshed.
    How can I know when the two queries has been refreshed?
    Is there any other way to do it?
    Any idea of how to reference a query from the other?
    I think the code shoud be in this way:
    for every row in the first colum of 1st query
    look in every row in the first column of 2nd query
    mark in first query if not present.
    If I put the macro in 1st query, how can I reference the 2nd one?

    Hi Oscar, there are several ways to do this.
    The easiest way would be:
    1.  in the SAPBEXonRefresh subroutine (which you will find in the SAPBEX Module attached to your query-containing workbook), add code that looks something like this:
    Set ws = resultArea.parent
    if ws is nothing then exit sub
    resultArea.name = ws.codename & "_results"
    ws.Range("D2") = Date
    if queryID = "SAPBEXq0002" then Call CompareQueries(queryID)
    'make the query ID that of the second query
    This will create named ranges in Excel so that you can easily locate the result tables later.  And, ensure that you know the date that each query was refreshed.  And, after the second query is refreshed, it will call your query comparison routine.
    2.  In the comparison routine, you will need something like this:
    set ws1 = Query1 'assuming that you have set the code name of the first query sheet as Query1
    set ws2 = Query2 'assuming that you have set the code name of the second query sheet as Query2
    'set ranges for the two result tables
    set Range1 = ws1.codename & "_results"
    set Range2 = ws2.codename & "_results"
    'locate first and last Row and Column for result tables
    firstRow1 = Range1.cells(1).row
    firstCol1 = Range1.cells(1).column
    numCells = Range1.cells.count
    lastRow1 = Range1.cells(numCells).row
    lastCol1 = Range1.cells(numCells).column
    'do same for Range2
    'locate the columns you want to compare
    searchCol = 0
    for j = firstCol1 to lastCol1
        if cells(firstRow1, j) like "some text here" then
            searchCol = j
            exit for
        end if
    next j
    if searchCol = 0 then
        msgbox "Did not find ""some text here"".", vbCritical
        exit sub
    Else:
        set SearchRange = ws1.cells(1, searchCol).entireColumn
    end if
    for j = firstCol2 to lastCol2
        if cells(firstRow2, j) like "some text here" then
            searchCol = j
            exit for
        end if
    next j
    'do the search
    for i = firstRow2 to lastRow2
        searchFor = cells(i, searchCol)
        matchRow = 0
        on error resume next
        matchRow = Application.worksheetfunction.match(searchFor, SearchRange, 0)
        if matchRow > 0 then
            cells(i, lastCol2+1) = "match found on row " & matchRow
        Else:
            cells(i, lastCol2+1) = "NOT PRESENT"
        End if
    next i
    - Pete

  • Creating query on Bex - Quaterly comparison for statistical & Actual

    Hi All,
    I would like to create a query for 'Quarterly comparison for statistical & Actual periods'.
    My Key Figures should be
    1) Plan 1st Qtr (Fiscal year, Period: 1 to 3, Value type : 1(Plan), Version : 0(Plan/actual), Valuation View: actual Value).
    2)1st Qtr (Fiscal year, Period: 1 to 3, "Value type : 4(Actual),11(Actual statistical)", Version : 0(Plan/actual), Valuation View: actual Value).
    3)Var 1st Qt (Plan 1st qtr - 1st Qtr)
    same thing for 4 Quaters. finally with
    4)Plan Year (Fiscal year, Period: 1 to 12, Value type : 1(Plan), Version : 0(Plan/actual), Valuation View: actual Value).
    I created a structure and created key figures with selections and formulas as required. But I did not see any data when I ran this query.
    The report was generated with 'no applicable data'.
    I need to create this query with plan 1st Qtr, Ist Qtr, Var 1st Qtr, Plan 2nd Qtr, 2nd Qtr, Var 2nd Qtr, Plan 3rd Qtr, 3rd Qtr, Var 3rd Qtr, Plan 4th Qtr, 4th Qtr, Var 4th Qtr, Plan year. key figures.
    Please let me know how can I create this query with these Key Figiures.
    Any help would be appreciated. Please respond with the reply.
    Thanks,
    Aparna.

    Hi
    The best way is then to run a report with your KF without any restriction, and the different chars in the drill down: Fiscal year, Period:, Value type,  Version , Valuation View
    Then you can check that you have some information with the combination of values of your chars:
    Fiscal year, Period: 1 to 3, Value type : 1(Plan), Version : 0(Plan/actual), Valuation View: actual Value.
    If you find a actual Value in the fiscal period you are looking at, for the period 1 to 3, for the Valuation type 1, for the version 0, then create arestricted KF by adding the restrictions one at a time....You moght discover why you do not get the results
    PY

  • BEx Query Designer 2 years comparison by month

    Hi expert,
    I'm drafting a report which want to comparison 2 years cost variance. I want to have 2 column inofmraiton, Cost & Variance % (which is  (Current Period - Previous Period) * 100/ Previous Period)  .
    I create the follow fields & defined a value range of  'CalYear/Month' in Filter of Characteristic Restrictions with variable offset value -12 which can input From mm.yyyy & To mm.yyyy.
    1. Characteristic of 'Cost'
    2. 'Cost -12' which is Cost with restriction of 'CalYear/Month' in 'From mm.yyyy' -12 to 'To mm.yyyy' -12 (HIDE FIELD)
    3. 'Variance %' which use function [ 'Cost' % 'Cost -12']
    After I Inputted the value of From Value 04.2011 & To Value 06.2011, it show 6 column of the cost in Apr 2010, May 2010, Jun 2010, Apr 2011, May 2011, Jun 2011, It show 0 under the 'Variance %' of Apr 2010, May 2010 & Jun 2010 is correct, but it can't calculate the any value of Variance % under Apr 2011, May 2011 & Jun 2011.
    Please advice
    Thanks & Regards
    Jack

    Create a CKF/formulae - then use Data Functions.
    Use SUMGT operator.
    SUMCT:
    It returns the result of the operand to all rows or columns
    SMGT:
    It returns the overall result of the operand
    SUMRT:
    It returns the query result of the operand
    How to use sumct, sumgt and sumrt
    http://help.sap.com/saphelp_nw04/helpdata/en/03/17f13a2f160f28e10000000a114084/frameset.htm
    Regards,
    rvc

  • Query of queries date comparison

    Cut to the basics, I'm trying to run the following code:
    <cfset qData = QueryNew("dataDate,ID")>
    <cfset padDate = "#DateFormat(Now(),"dd mmm yy")#
    23:59">
    <cfset queryAddRow(qData)>
    <cfset QuerySetCell(qData,"ID",1)>
    <cfset QuerySetCell(qData,"dataDate",padDate)>
    <cfset delDate = "#DateFormat(Now(),"dd mmm yy")#
    00:00">
    <cfquery name="qZero" dbtype="query">
    SELECT ID
    FROM qData
    WHERE dataDate = '#delDate#'
    </cfquery>
    This works fine in MX7 but I need to put it on a server using
    MX6.1. It appears that in 6.1 query of queries considers the
    dataDate field to be a date but will not accept a date on the right
    hand side of the equals sign in the where clause so comes up with
    'Unsupported type comparison'. Is there any way round this?

    I just ran into this problem actually.
    What appears to be happening is QoQ has trouble comparing SQL
    date types and DB date types. I had to perform an lsdateformat on
    the data to get it to process.
    I am also looking into a problem where QoQ is switching my
    dates to strings. CF has yet to impress me. For every kind of cool
    thing they do there are 25 lame things.

  • Query Builder - Where Clause - Could not format error using date comparison

    We've come across a bug in the Query Builder, under the Create Where Clause tab, if you select a column of Date type plus one of the comparison operators =, !=, <, >, <=, >=, BETWEEN or NOT BETWEEN it displays an error in the Logging Page:
    Level: Severe
    Source: o.d.r.queryBuilder.SQLGenerator
    Message: Could not format :2010-09-02 16:20:31.0
    Then under the Show SQL tab it doesn't display the date(s) you selected, e.g.
    WHERE LAST_UPDATE BETWEEN AND
    Also the View Results tab does not display any results.
    You can still press Apply to add the SQL as is to the editor window and from there you have to manually code in the date parameters.
    We're using the latest version of SQL Developer 2.1.1.64.45 Windows 32bit version with JDK

    Hi Gordon,
    When I add the following lines:
    declare @refdt1 date
    set @refdt =
    /*select 1 from jdt1 t0 where t0.RefDate*/ '[%1]'
    declare @refdt2 date
    set @refdt =
    /*select 1 from jdt2 t0 where t0.RefDate*/ '[%2]'
    WHERE T0.RefDate >= @refdt1 and T0.RefDate <= @refdt2
    ... the error message is now:
    Must declare the scalar variable @refdt1
    Note: Before adding these lines, the query works perfectly, and returns totals from the whole database (with dynamically generated column headings!)
    Thanks
    Leon Lai
    AMENDED QUERY:
    declare @refdt1 date
    set @refdt1 =
    /*select 1 from jdt1 t0 where t0.RefDate*/ '[%1]'
    declare @refdt2 date
    set @refdt2 =
    /*select 1 from jdt1 t0 where t0.RefDate*/ '[%2]'
    --------- I inserted the 6 lines above ---------------------
    DECLARE @listCol VARCHAR(2000)
    DECLARE @query VARCHAR(4000)
    SELECT @listCol =
    STUFF
    ( SELECT DISTINCT   '],['    +    CAST(month(T0.RefDate) AS varchar)
    FROM  JDT1 T0
    FOR XML PATH('')
    ), 1, 2, ' ') +   ']'
    SET @query =
    'SELECT * FROM
    (SELECT Account, month (T0.RefDate) Month , Debit
    FROM JDT1 T0
    ------------------- I add the WHERE clause below --------------------
    WHERE T0.RefDate >= @refdt1 and T0.RefDate <= @refdt2
    GROUP BY Account, RefDate, Debit
    ) S
    PIVOT
    Sum(Debit)
    FOR Month IN ('+@listCol+')
    ) AS pvt'
    EXECUTE (@query)
    Edited by: LEONLAI on Oct 21, 2011 2:36 PM

  • Comparison query

    I have a table called vehicle_density. Following are the sample data of this table.
    Period          Vehicle       Location
    Jan-2009     300     Jayanagar
    Fab-2009     245     Jayanagar
    Mar-2009     236     Jayanagar
    Apr-2009     298     Jayanagar
    May-2009     325     Jayanagar
    Jun-2009     204     Jayanagar
    Jan-2009     568     BTM
    Fab-2009     585     BTM
    Mar-2009     401     BTM
    Apr-2009     565     BTM
    May-2009     621     BTM
    Jun-2009     425     BTM
    Jan-2009     145     RT Nagar
    Fab-2009     200     RT Nagar
    Mar-2009     254     RT Nagar
    Apr-2009     120     RT Nagar
    May-2009     282     RT Nagar
    Jun-2009     96     RT NagarNow I need a query to compare vehicle density between different locations for given time period.
    For example here is sample output vehicle density comparison between BTM and Jayanagar between Jan-2009 to Mar-2009
    Period       Jayanagar   BTM
    Jan-2009     300     568
    Fab-2009     245     585
    Mar-2009     236     401Same way density comparison between jayanagar, BTM and RT Nagar between Jan-2009 to Mar-2009 is below
    Period     Jayanagar     BTM     RT Nagar
    Jan-2009     300     568     145
    Fab-2009     245     585     200
    Mar-2009     236     401     254
    Apr-2009     298     565     120Can I do it in single sql query?
    Thanks,
    Sujnan

    Hi, Sujnan,
    Yes, you can do that in one query. It's called a pivot.
    One way is shown below. This example uses the COUNT function; for what you want, use SUM instead.
    Search for "pivot" or "rows to columns" for more examples.
    --     How to Pivot a Result Set (Display Rows as Columns)
    --     For Oracle 10, and earlier
    --     Actually, this works in any version of Oracle, but the
    --     "SELECT ... PIVOT" feature introduced in Oracle 11
    --     is better.  (See Query 2, below.)
    --     This example uses the scott.emp table.
    --     Given a query that produces three rows for every department,
    --     how can we show the same data in a query that has one row
    --     per department, and three separate columns?
    --     For example, the query below counts the number of employess
    --     in each departent that have one of three given jobs:
    PROMPT     ==========  0. Simple COUNT ... GROUP BY  ==========
    SELECT     deptno
    ,     job
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ,          job;
    Output:
        DEPTNO JOB              CNT
            20 CLERK              2
            20 MANAGER            1
            30 CLERK              1
            30 MANAGER            1
            10 CLERK              1
            10 MANAGER            1
            20 ANALYST            2
    PROMPT     ==========  1. Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno;
    --     Output:
        DEPTNO ANALYST_CNT  CLERK_CNT MANAGER_CNT
            30           0          1           1
            20           2          2           1
            10           0          1           1
    --     Explanation
    (1) Decide what you want the output to look like.
         (E.g. "I want a row for each department,
         and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
    (2) Get a result set where every row identifies which row
         and which column of the output will be affected.
         In the example above, deptno identifies the row, and
         job identifies the column.
         Both deptno and job happened to be in the original table.
         That is not always the case; sometimes you have to
         compute new columns based on the original data.
    (3) Use aggregate functions and CASE (or DECODE) to produce
         the pivoted columns. 
         The CASE statement will pick
         only the rows of raw data that belong in the column.
         If each cell in the output corresponds to (at most)
         one row of input, then you can use MIN or MAX as the
         aggregate function.
         If many rows of input can be reflected in a single cell
         of output, then use SUM, COUNT, AVG, STRAGG, or some other
         aggregate function.
         GROUP BY the column that identifies rows.
    PROMPT     ==========  2. Oracle 11 PIVOT  ==========
    WITH     e     AS
    (     -- Begin sub-query e to SELECT columns for PIVOT
         SELECT     deptno
         ,     job
         FROM     scott.emp
    )     -- End sub-query e to SELECT columns for PIVOT
    SELECT     *
    FROM     e
    PIVOT     (     COUNT (*)
              FOR     job     IN     ( 'ANALYST'     AS analyst
                             , 'CLERK'     AS clerk
                             , 'MANAGER'     AS manager
    NOTES ON ORACLE 11 PIVOT:
    (1) You must use a sub-query to select the raw columns.
    An in-line view (not shown) is an example of a sub-query.
    (2) GROUP BY is implied for all columns not in the PIVOT clause.
    (3) Column aliases are optional. 
    If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query for Balance Sheet comparison Actual/Plan

    Hello,
    I try to create a query in the BEx using the cube 0FIGL_V10 to display the balance sheet and p/l statement in BI. It works fine with comparison actual/actual but I don't know how to make a comparison between actual and plan figures.
    I am using as filter criteria the dimensions value type ([0VTYPE 10 which is actual and 0VTYPE 20 which is plan). But how is it possible to display it in the right line and columns.
    I need to fix this be the end of next week. So please answer as soon as you can.
    Thanks a lot for your help.
    Regards
    Robert

    Hello Sam,
    thanks a lot for you pretty good answer. It works perfectly but there is one thing left, maybe you can answer that too:
    I want to display 3 actual periods but only one plan period. How can I realize this?
    Thanks again for your prompt help.
    Regards
    Robert

  • Query about date comparison

    Hi,
    I have a database table with a date field called 'ENDDAT'
    How do I write a select query that selects all records whose difference between sy-datum and 'ENDDAT' is greater than 7.
    If I do the normal date comparison for eg.
    select * from <databasetable> where enddat - sy-datum > 7
    or
    select * from <databasetable> where (enddat - sy-datum) > 7
    It throws error that '-' is not a valid comparison operator.
    Can anyone help????

    I've never seen that done before.  You can do as joseph has suggested.   If you can do it in the select statement, I'm not really sure that you'd want to put that kind of processing on the database.
    data: begin of itab occurs 0,
          enddat type sy-datum,
          end of itab.
    select * into corresponding fields of table itab
           from <databasetable> .
    data: cdatum type sy-datum.
    Loop at itab.
    cdatum = enddat - sy-datum
    * if <= 7, then delete from itab.
    if cdatum <= 7.
    delete itab.
    endif.
    endloop.
    Regard,
    Rich Heilman

  • Is there a speed  comparison between xpath query

    Is there a paper whit speed comparison between xpath query on XML, stored with all oracle's techniques?
    Thank you and sorry for my english

    Not currently. Since there are no industry standards for XML benchmarks that are accepted by all major vendors Oracle policy prevents us from publishing numbers. However if you have examples of what you are looking for I can give guidance.

  • Error signaled in parallel query server p005 DATE format comparison

    Hello All,
    I have a data like this.
    {code}
    j_id   s_id     b_id    lc   t_date                             my_val1     my_val2
    100    200    300     prs   2013-07-17 16:01:47         myval1     myval2
    100    200   300     prs    2013-07-17 16:01:47         myCval1   myCval2
    {code}
    When i am running a query like this
    {code}
    update my_tab b
            set my_col = 'X'
            where rowid <> ( select max(t.rowid) from my_tab t
                             where
                                    t.J_ID        = b.J_ID   and
                                    t.S_ID = b.S_ID and
                                    t.B_ID      = b.B_ID and
                                    t.LC   = b.LC
                                  and TO_TIMESTAMP(trim(t.t_DATE), 'YYYY-MM-DD HH24:MI:SS.FF')
                                   = TO_TIMESTAMP(trim(b.t_DATE), 'YYYY-MM-DD HH24:MI:SS.FF')
    {code}
    I know i have a DATE format but converting it into TIMESTAMP because my data is random and could contain the time stamp as well.
    My concern here is when i run above update statement i get error
    {code}
    ORA-12801: error signaled in parallel query server P005
    ORA-01862: the numeric value does not match the length of the format item
    {code}
    but when i do like below.. It runs fine. Not sure what i am missing here or doing something wrong. Please help.
    {code}
    select to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF') from dual
    where
    to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF') = to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF')
    {code}
    Thanks!

    user10647455 wrote:
    Hello All,
    I have a data like this.
    {code}
    j_id   s_id     b_id    lc   t_date                             my_val1     my_val2
    100    200    300     prs   2013-07-17 16:01:47         myval1     myval2
    100    200   300     prs    2013-07-17 16:01:47         myCval1   myCval2
    {code}
    When i am running a query like this
    {code}
    update my_tab b
            set my_col = 'X'
            where rowid <> ( select max(t.rowid) from my_tab t
                             where
                                    t.J_ID        = b.J_ID   and
                                    t.S_ID = b.S_ID and
                                    t.B_ID      = b.B_ID and
                                    t.LC   = b.LC
                                  and TO_TIMESTAMP(trim(t.t_DATE), 'YYYY-MM-DD HH24:MI:SS.FF')
                                   = TO_TIMESTAMP(trim(b.t_DATE), 'YYYY-MM-DD HH24:MI:SS.FF')
    {code}
    I know i have a DATE format but converting it into TIMESTAMP because my data is random and could contain the time stamp as well.
    My concern here is when i run above update statement i get error
    {code}
    ORA-12801: error signaled in parallel query server P005
    ORA-01862: the numeric value does not match the length of the format item
    {code}
    but when i do like below.. It runs fine. Not sure what i am missing here or doing something wrong. Please help.
    {code}
    select to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF') from dual
    where
    to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF') = to_timestamp('2013-07-08 17:58:47', 'YYYY-MM-DD HH24:MI:SS.FF')
    {code}
    Thanks!
    If you have a date column, converting that to a timestamp isn't going to magically add more information to the date.
    Date data types hold time information (not to the fractional precision like timestamps, but up to the second) ... if you are having a problem seeing that information, it's likely because of your NLS_DATE_FORMAT setting (whatever client you are using to view the data isn't showing you all of the information, but it's still there).
    So basically, this boils down to your code not "making sense" at the moment
    Cheers,

Maybe you are looking for