Error analytic function

Hi all
SELECT chp.acct_nbr,CHP.INBOX_ID,
       MAX (CHP.INBOX_ID) OVER (PARTITION BY chp.ACCT_NBR)
                                                            
       NULL, 'TMQ', NULL,
       row_number() OVER (PARTITION BY CHP.ACCT_NBR ORDER BY CHP.INBOX_ID desc) AS MAXM
  FROM chapsapp.mod_qual chp
  WHERE
  MAXM=1
gives error for maxm as invalid identifier.

Hello

AJR says:
Hi all

SELECT chp.acct_nbr,CHP.INBOX_ID,
MAX (CHP.INBOX_ID) OVER (PARTITION BY chp.ACCT_NBR)

NULL, 'TMQ', NULL,
row_number() OVER (PARTITION BY CHP.ACCT_NBR ORDER BY CHP.INBOX_ID desc) AS MAXM
FROM chapsapp.mod_qual chp
WHERE
MAXM=1

gives error for maxm as invalid identifier.

You cannot reference an alias for column (like MAXM) in the same request where it is defined. (Actually, there is one exception: in the ORDER BY clause.)
Also, the analytic function are calculated after the WHERE clause is applied, you cannot use analytics in the WHERE clause.

The solution to these two problems is to calculate the analytical functions in a subquery, and then reference them in the clause WHERE (or wherever you want) a Super application.

So you're got query mutilated, but I think you are trying to do something like this:

WITH    got_maxm    AS
(
    SELECT  chp.acct_nbr
    ,         CHP.INBOX_ID
    ,       MAX (CHP.INBOX_ID) OVER (PARTITION BY chp.ACCT_NBR)          AS x
    ,       row_number ()      OVER (PARTITION BY CHP.ACCT_NBR
                                                ORDER BY    CHP.INBOX_ID   desc
                        )                         AS MAXM
       FROM  chapsapp.mod_qual chp
)
SELECT  acct_nbr
,     inbox_id
,     x
,     NULL
,     'TMQ'
,     NULL
,     maxm
FROM     got_maxm
WHERE     maxm     = 1
;

Tags: Database

Similar Questions

  • The appropriate to a MAX on an analytical function syntax

    I am trying to apply a MAX function on a function analytically than doing a MAX as well. However, I can't understand the appropriate syntax. That's what I tried:
    SELECT MAX(MAX(t.col1) OVER (PARTITION BY t.col2) AS max_col
      FROM sample_table t;
    When I try to run the above query, I get a 't.col1 is invalid in the select list because it is not contained in an aggregate function or the GROUP BY clause error.

    You must encapsulate the query that has the analytical function in another query and then make the max in the outer query.

  • problem of analytic function

    Hello

    I have a problem using the analytical function: when I run this query

    SELECT TSIUPSITE, TSIUPCEAN, TSIUPDATE, sum (TSIUPCA) TSIUPCA, TSIUPCTVA, TSIUPP4N, TSIUPPIEC,.
    Sum (TSIUPQTE) TSIUPQTE, sum (TSIUPQTEP) TSIUPQTEP, TSIUPMDIU, TSIUPMDar,
    Sum (TSIUPCRIU) TSIUPCRIU, sum (TSIUPCRAR) TSIUPCRAR, trunc (TSIUPDCRE) TSIUPDCRE, trunc (TSIUPDMAJ) TSIUPDMAJ,
    TSIUPUTIL, TSIUPTRT, TSIUPNERR, TSIUPMESS.
    TSIUPTMVT, TSIUPSMAN, TSIUPMOTIF, sum (TSIUPMHT) TSIUPMHT, 0 vtanfisc.
    TSIUPDATEVERIF, TSIUPNSEQ, TSIUPCINV, count (*) over (partition TSIUPSITE, TSIUPCEAN, TSIUP_TRT) CONTA_ARTICOLO
    OF TST_FLIISR_VTEREMART
    WHERE 1 = 1 - TSIUP_TRT = 1
    AND TSIUPDATE = to_date('27082012','ddmmyyyy')
    and TSIUP_NTRX = 172
    AND TSIUPSITE = 10025
    AND TSIUPCEAN = '8012452018825'
    GROUP OF TSIUPSITE, TSIUPCEAN, TSIUPDATE, TSIUPCTVA, TSIUPP4N, TSIUPPIEC,
    TSIUPMDIU, TSIUPMDar, trunc (TSIUPDCRE), trunc (TSIUPDMAJ), TSIUPUTIL, TSIUPTRT, TSIUPNERR, TSIUPMESS,
    TSIUPTMVT, TSIUPSMAN, TSIUPMOTIF, 0,
    TSIUPDATEVERIF, TSIUPNSEQ, TSIUPCINV
    ORDER OF TSIUPSITE, TSIUPDATE;

    I have the error ORA-00979: not an expression GROUP BY related to the area of TSIUP_TRT, infact, if I run it

    SELECT TSIUPSITE, TSIUPCEAN, TSIUPDATE, sum (TSIUPCA) TSIUPCA, TSIUPCTVA, TSIUPP4N, TSIUPPIEC,.
    Sum (TSIUPQTE) TSIUPQTE, sum (TSIUPQTEP) TSIUPQTEP, TSIUPMDIU, TSIUPMDar,
    Sum (TSIUPCRIU) TSIUPCRIU, sum (TSIUPCRAR) TSIUPCRAR, trunc (TSIUPDCRE) TSIUPDCRE, trunc (TSIUPDMAJ) TSIUPDMAJ,
    TSIUPUTIL, TSIUPTRT, TSIUPNERR, TSIUPMESS.
    TSIUPTMVT, TSIUPSMAN, TSIUPMOTIF, sum (TSIUPMHT) TSIUPMHT, 0 vtanfisc.
    TSIUPDATEVERIF, TSIUPNSEQ, TSIUPCINV, count (*) over (partition TSIUPSITE, TSIUPCEAN) CONTA_ARTICOLO
    OF TST_FLIISR_VTEREMART
    WHERE 1 = 1 - TSIUP_TRT = 1
    AND TSIUPDATE = to_date('27082012','ddmmyyyy')
    and TSIUP_NTRX = 172
    AND TSIUPSITE = 10025
    AND TSIUPCEAN = '8012452018825'
    GROUP OF TSIUPSITE, TSIUPCEAN, TSIUPDATE, TSIUPCTVA, TSIUPP4N, TSIUPPIEC,
    TSIUPMDIU, TSIUPMDar, trunc (TSIUPDCRE), trunc (TSIUPDMAJ), TSIUPUTIL, TSIUPTRT, TSIUPNERR, TSIUPMESS,
    TSIUPTMVT, TSIUPSMAN, TSIUPMOTIF, 0,
    TSIUPDATEVERIF, TSIUPNSEQ, TSIUPCINV
    ORDER OF TSIUPSITE, TSIUPDATE;

    I have no problem. Now the difference between the TSIUPCEAN (or TSIUPSITE) and TSIUP_TRT that TSIUP_TRT is not in the Group By clause, but, to be honest, I don't know why I have this problem using using an analytic function.

    Thanks for help

    Hello

    I think that you are not analytic function correctly.

    Analytical functions will be run for each line. Where as Group BY will run for groups of data.

    See example below for you reference.

    Example 1:
    
    -- Below query displays number of employees for each department. Since we have used analytical function for each row you are getting the number of employees based on the department id.
    
    SQL> SELECT e.department_id,count(*) OVER (PARTITION BY e.department_id) cnt_analytic
      2  FROM employees e
      3  WHERE e.department_id IN (10,20,30);
    
    DEPARTMENT_ID CNT_ANALYTIC
    ------------- ------------
               10            1
               20            2
               20            2
               30            6
               30            6
               30            6
               30            6
               30            6
               30            6
    
    9 rows selected.
    
    Example 2:
    
    -- Since I have used GROUP BY clause I'm getting only single row for each department.
    
    SQL> SELECT e.department_id, count(*) cnt_group
      2  FROM employees e
      3  WHERE e.department_id IN (10,20,30)
      4  GROUP BY e.department_id;
    
    DEPARTMENT_ID  CNT_GROUP
    ------------- ----------
               10          1
               20          2
               30          6
    

    Finally, what I'm trying to explain is - if you use the analytical function with the GROUP BY clause, the query will not give the ful menaing result set.

    See below

    SQL> SELECT e.department_id,count(*) OVER (PARTITION BY e.department_id) cnt_analytic, count(*) cnt_grp
      2  FROM employees e
      3  WHERE e.department_id IN (10,20,30)
      4  GROUP BY e.department_id;
    
    DEPARTMENT_ID CNT_ANALYTIC    CNT_GRP
    ------------- ------------ ----------
               10            1          1
               20            1          2
               30            1          6
    
  • Try to use a function of Group on an analytic function

    Hello

    We use the Oracle 11.1.

    I have an analytic function that gives me the DENSE_RANK of lines groups. I would like to return the highest value of each group.

    The function looks like:
    DENSE_RANK( ) OVER (PARTITION BY METRIC ORDER BY sum(AEROBIC_EXERCISE_P1), COACHID)
    When I try to use:
    MAX(DENSE_RANK( ) OVER (PARTITION BY METRIC ORDER BY sum(AEROBIC_EXERCISE_P1), COACHID))
    I have get and error
    ORA-30483: window  functions are not allowed here
    Is it possible that I can do this?

    Hello

    Sorry, my mistake. You do not have an ORDER BY clause analytic it.

    COUNT (DISTINCT SUM (aerobic_exercise_p1)) OVER (PARTITION BY  metric)
    

    If you would post CREATE TABLE and INSERT statements, then I could test it.

  • [8i] can I use an analytical function, or do I need a subquery?

    Hi all...

    This should be a quick. I hope I can solve my problem with an analytic function, but I don't know if it's possible. Can I use a subquery if I have to, but I'd really rather not.

    Here is a very simple version of what I'm trying to do:
    CREATE TABLE     test123
    (     field1          VARCHAR2(10)
    ,     field2          VARCHAR2(10)
    ,     my_date          DATE
    );
    
    INSERT INTO     test123
    VALUES     ('value1', 'a',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value1', 'b',TO_DATE('01/02/2010','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value1', 'c',TO_DATE('01/05/2010','mm/dd/yyyy'));
    
    INSERT INTO     test123
    VALUES     ('value2', 'a',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value2', 'b',TO_DATE('01/01/2010','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value2', 'c',TO_DATE('01/15/2010','mm/dd/yyyy'));
    I want the results:
    FIELD1     FIELD2
    --------------
    value2     a
    value2     b
    value2     c
    value1     a
    value1     b
    value1     c
    I started with the following query:
    SELECT     field1
    ,          field2
    FROM     test123
    ORDER BY     MIN(my_date)     OVER     (
                                                 PARTITION BY     field1
                                                 )                                -- removed DESC here
    ,               field2
    But the problem is the database has a date of 31 December 1900 ' as default / initial for any date field. I don't want these default values taken into account in my calculation of min. I tried to put a WHERE clause in my analytical function [WHERE my_date <>TO_DATE (' 12/31/1900 ',' mm/dd/yyyy')], but I kept getting an error message "missing right parenthesis", so it seems that you can not have a WHERE clause here... or I'm just something wrong?

    Moreover, it is a 8i database...

    Edited by: user11033437 may 20, 2010 17:16: took the 'DESC' criteria out of my order by clause. In my real application, I need DESC, but not the example.

    Hello

    A WHERE clause excludes rows in the results set. Whenever you want you can have a WHERE clause that was more limited (for example, something that would simply exclude MIN calculating values in the ORDER BY clause), then think CASE:

    SELECT       field1
    ,       field2
    FROM       test123
    ORDER BY  MIN ( CASE
                  WHEN  my_date > TO_DATE ( '12/31/1900'
                                 , 'MM/DD/YYYY'
                                 )
                  THEN  my_date
              END
               )     OVER     (PARTITION BY     field1)      DESC
    ,       field2
    ;
    

    This puts the lines for "Value1" first.
    The minimum my_date for "Value1" (after excluding the values of 1900) is later than the minimum for "Value2", so I think that you either made a mistake in the desired output, or you do not want sorted by descending order.

    As always, thanks for the display of the data of the sample and the results so clearly.

  • Analytical function - max_distinct

    Hello world

    (a) I have a request tht returns multiple rows for a student

    (b) to simplify my query, is columns

    Student ID, Academic_Period, student, Expected_Graduation_Date status

    (c) If a student has several status codes
    AS - active
    THE - leave

    He gets 2 rows to display.

    (d) I want to show only the rows

    Maximum preference on the Date of graduation

    (e) so I made this calc:

    MAX_DISTINCT (Expected_Graduation_Date) OVER (PARTITION BY ID.)

    and received the error:
    data types incompatible number got date scheduled

    (f) so I did:

    MAX_DISTINCT (TO_NUMBER (Expected_Graduation_Date)) OVER (PARTITION BY ID.)

    and received the error:
    invalid number

    (g) so I changed to max on alpha field of: student status
    MAX_DISTINCT (student status) OVER (PARTITION BY Id)

    and received the error:
    invalid number

    (h) is the right function to use?
    What's doing FIRST_VALUE.

    Your ideas and your advice would be appreciated, tx, Sandra

    Hello

    You need not use analytical functions. Try to create these calculations to replace the columns where there are different values:

    student_status_last = keep max (student_status) (last dense_rank order by Expected_Graduation_Date)

    Expected_Graduation_Date_last = max (Expected_Graduation_Date)

    Rod West

  • Consolidation of the unauthorized analytical functions

    Hi all, I have a calculated field named Calculation1 with the following calculation:

    AVG (Resolution_time) KEEP (DENSE_RANK FIRST ORDER BY RANK) OVER (PARTITION BY "The COMPLETE user groups". Name of the group, "notes report COMPLETE #7. Name of the resource)

    The result of this calculation is correct, but is repeated for all the rows in the dataset.
    Group Name      Resourse name    Calculation1

    SH Group            Mr. A            10
    SH Group            Mr. A            10
    SH Group            Mr. A            10
    SH Group            Mr. A            10
    SH Group            Mr. A            10
    ...............................................
    5112 rows
    I tried to create another calculation to have only one value for the couple "(nom dele de groupe, le nom de la ressource) like AVG (Calculation1) but I got the error: unauthorized consolidation of analytical functions"

    I have also seen inside the spreadsheet "Edit" Panel that the Calculation1 * is not represented * with the "Sigma" symbol I (like for instance a simple (field_1) AVG) and inside the SQL, I did not GROUP BY group name, name of the resource...

    I would like to see ONLY a line like:
    Group Name      Resourse name    Calculation1

    SH Group            Mr. A            10
    .. .that means I've grouped by group name, name of the resource

    Anyone know how I can get this result or any workaround?

    Thanks in advance

    Alex

    Hello

    You can do this completely in the workbook because you need to aggregate several times. You need computing rank as a calculated using Disco admin folder item.

    Then you should be able to use

    AVG (CASE WHEN STATUS = 1 THEN Resolution_time END)

    in the workbook.

    Rod West

  • A question about the analytical function used with the GROUP BY clause in SHORT

    Hi all

    I created the following table named myenterprise
    CITY       STOREID    MONTH_NAME TOTAL_SALES            
    ---------- ---------- ---------- ---------------------- 
    paris      id1        January    1000                   
    paris      id1        March      7000                   
    paris      id1        April      2000                   
    paris      id2        November   2000                   
    paris      id3        January    5000                   
    london     id4        Janaury    3000                   
    london     id4        August     6000                   
    london     id5        September  500                    
    london     id5        November   1000
    If I want to find which is the total sales by city? I'll run the following query
    SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    that works very well and produces the expected result, i.e.
    CITY       TOTAL_SALES_PER_CITY   
    ---------- ---------------------- 
    london     10500                  
    paris      17000            
    Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:
    SELECT city, 
           SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).

    Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
    SELECT city, 
           SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    This generates the following error:
    Error starting at line 2 in command:
    SELECT city, 
           SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY
    Error at Command Line:2 Column:11
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 -  "not a GROUP BY expression"
    *Cause:    
    *Action:
    The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.

    So here's my question:

    Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?


    Thanks in advance!
    :)





    In case you are interested, that's my definition of the table:
    DROP TABLE myenterprise;
    CREATE TABLE myenterprise(
    city VARCHAR2(10), 
    storeid VARCHAR2(10),
    month_name VARCHAR2(10),
    total_sales NUMBER);
    
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'January', 1000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'March', 7000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'April', 2000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id2', 'November', 2000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id3', 'January', 5000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id4', 'Janaury', 3000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id4', 'August', 6000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id5', 'September', 500);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id5', 'November', 1000);
    Edited by: dariyoosh on April 9, 2009 04:51

    It is clear that thet Analytics is reduntant here...
    You can even use AVG or any analytic function...

    SQL> SELECT city,
      2         avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
      3  FROM myenterprise
      4  GROUP BY city
      5  ORDER BY city, TOTAL_SALES_PER_CITY;
    
    CITY       TOTAL_SALES_PER_CITY
    ---------- --------------------
    london                    10500
    paris                     17000
    
  • Analytic function to summarize

    Hi, I have a question regarding the analytical functions.

    SCENARIO OF
    I have two fields: TICKET_ID and TASK_TIME

    For each TICKET_ID, I have a task_time calculated as in the example:
     
    TICKET_ID                            TASK_TIME
    112293                                 25                                   
    112294                                 1200                                 
    112294                                 40                                   
    112295                                 40                                   
    112296                                 60                                   
    112297                                 120                                  
    112298                                 60                                   
    112299                                 60                                   
    112300                                 180                                  
    112301                                 1440                                 
    112302                                 4320                                 
    112303                                 120                                  
    112304                                 306                                  
    TASK_TIME calculation is the following: IPTV_COUNT_TASKS_TIME (JTF_TASKS_B.Task Id: CREATION_DATE_UL)

    where:

    IPTV_COUNT_TASKS_TIME is a function of DB
    JTF_TASKS_B.Task Id is an area from runtime
    : CREATION_DATE_UL is a parameter after PERIOD


    As you can see the 112294 ticket I have 2 rows.
    What I want to achieve is the following: I would like to have average task_time (taking into account all tickets), but I don't want to count 2 times the ticket 112294

    So... What have I done?
    I create another calculated field named SUM (Task_time) where the calculation is: SUM (TASK_TIME) OVER (PARTITION OF TICKET_ID)
    and I got:
     
    TICKET_ID                            TASK_TIME
    112293                                 25                                   
    112294                                 1240  
    112294                                 1240                               
    112295                                 40                                   
    112296                                 60                                   
    112297                                 120                                  
    112298                                 60                                   
    112299                                 60                                   
    112300                                 180                                  
    112301                                 1440                                 
    112302                                 4320                                 
    112303                                 120                                  
    112304                                 306                                  
    .. .and it isn't good, because, in order to calculate the AVG (TASK_TIME) I want to have only one ticket 112294 (and see only once the value of 1240)
    In other words, I need to summarize the task_time for each ticket and show the result only once for each ticket.

    Where is the error? How I do change the SUM (Task_time) calculation?

    Thanks in advance for any suggestion

    Alex

    Hello

    You can create the package in a schema, although usually an APPS environment I would create the package in the APPS schema because then you need not to grant privileges.

    Rod West

  • Error installing Fallout 3:-'Default functionality', component 'Fallout3', file: E:\data2 cab, error "incorrect function".

    Original title: 'Incorrect function' Fallout 3

    I have Vista 32-bit, all the elements for Fallout 3. It starts to install then a box pops up saying characteristic-'Default Feature', component 'Fallout3', file: E:\data2 cab, error "incorrect function".  I have the original disc, no copy, I cleaned the disc. I don't know what else to do?

    Hi tsp2u61,

    Usually, when you get this error, it means that your CD cannot be read.

    You can check if the drive works in another computer to make sure that the disk is not damaged.

    You can try to copy all the contents of the installation of the drive on the local hard drive and install from there and check if you can install

    a. right click on the desktop, create a new folder and name it as Fallout 3

    b. Insert the diskette in Fallout 3

    c. Click Start and open computer.

    d. right-click on the CD / DVD drive and click Open.

    e. press the Alt key and click on modify.

    f. click on select all.

    g. still once, press the ALT key and click on copy.

    h. Ouvrezledossier Fallout 3 on the desktop.

    i. press the Alt key and click on paste.

    Now try to install files copied on the desktop and check if it works very well.

    If this is not enough, you may need to get in touch with the help of the game maker.

    Bethesda Softworks Forums-> Fallout

    http://forums.bethsoft.com/index.php?/forum/40-fallout/

    Hope this information is useful.

    Jeremy K
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • GGetting advapi32.dll error invalid function on bootcamp

    Original title: at the start, I am reciving an error "invalid function advapi32.dll" almost all start-ups. How can I troubleshoot this to clear the error?

    Do not know what is the origin, online searches, just trying to sell me programs to erase it. some answers say hardware problems, software. all my gear works as far as I can see, no errors in the hardware Manager.

    Win xp SP3.

    Thanks in advance for any help!

    You are welcome. Marking of one (or several) of our responses as RESPONSE will officially close your thread. (No, you can't score a the answers as RESPONSE.)

  • Cannot use analytical functions such as lag/lead in odi components 12 c except in the expression

    Hi I am a beginner of ODI 12 c

    I'm trying to get the last two comments made on the product for a given product id. and load them into a target.

    I have a source table something like

    Product SR_NO comments LAST_UPDATED_TS

    1 good car 2015/05/15 08:30:25

    1 car average 2015/05/15 10:30:25

    Jeep 2 super 2015/05/15 11:30:25

    1 car bad 2015/05/15 11:30:25

    Jeep 2 horrible 2015/05/15 09:30:25

    Jeep 2 excellent 2015/05/15 12:30:25


    I want a target table based on their last timestamp updated as (last two comments)


    SR_NO Comment1 Comment2

    1                             bad                      average

    2 super excellent

    I used the logic below to get records in SQL Developer but in ODI 12 c, I'm not able to do this by mapping a source to the target table by applying analytical functions to the columns in the target table. Can someone help me solve this problem

    SELECT * FROM)

    SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),

    ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)

    FROM Source_table

    ) M

    WHERE RN = 1

    ;

    UM, I'm afraid that ODI puts the filter too early in the request, if it generates:

    SELECT * FROM)

    SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),

    ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)

    FROM Source_table

    WHERE RN = 1

    ) M

    ;

    Instead of:

    SELECT * FROM)

    SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),

    ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)

    FROM Source_table

    ) M

    WHERE RN = 1

    ;

    Even by changing the 'run on Hint"of your component of the expression to get there on the source, the request will stay the same.

    I think the easiest solution for you is to put everything before the filter in a reusable mapping with a signature of output. Then drag this reusable in your mapping as the new source and check the box "subselect enabled."

    Your final mapping should look like this:

    It will be useful.

    Kind regards

    JeromeFr

  • Which analytical function to use?


    Hi gurus,

    DB - Oracle 11 g 2

    I followed the examples of data in the table test_a.

    col1 col2 col3

    -----            -------            --------

    x                 y                   y

    p                 q                  y

    a                b                   y

    p                q                   y

    t                 r                    y

    p                q                   y

    The col3 column is always 'y '. But here's the data p, q, there is repeated 3 times (duplicate) and if this is the case I want to update only the first recordings like "n" col3 it is to say p, q, n. rest will be as it is.

    I am able to get the row_number() for it but not able to do this.

    Select col1, clo2, clo3 row_number() over (partition by col2) arrested by col1 as test_a r_num

    Would it be possible directly by any analytic function?

    Thank you

    SID

    COL4 is logical...

    Something like that?

    with x as)

    Select col1, col2 ' x' 'y', 'y' col3 col4 1 Union double all the

    Select 'p' col1, col2 'q', 'y' col3 col4 2 Union double all the

    Select 'a' col1, col2 'b', 'y' col3 col4 3 of all the double union

    Select 'p' col1, col2 'q', 'y' col3 col4 4 Union double all the

    Select 't' col1, col2 'r', 'y' col3, col4 5 Union double all the

    Select 'p' col1, col2 'q', 'y' col3 col4 6 double

    )

    ---

    Select * from)

    Select x.*,

    ROW_NUMBER() on rn1 (score of col1, col2, col3 col4 sort),

    ROW_NUMBER() on rn2 (partition by col1, col2, col3 col4 desc sorting)

    x

    )

    where rn1 = 1 and rn2 <> 1;

    Understand the logic and simply change SELECT a query to UPDATE...

  • Using the analytic function

    Oracle 11g Release 2

    I'm assuming that the best solution is the use of analytical functions.

    create table test3
    ( part_type_id  varchar2(50)
    ,group_id      number
    ,part_desc_id  number
    ,part_cmt      varchar2(50)
    )
    /
    
    insert into test3 values( 'ABC123',1,10,'comment1');
    insert into test3 values( 'ABC123',1,10,'comment2');
    insert into test3 values( 'ABC123',2,15,'comment1');
    insert into test3 values( 'ABC123',2,15,'comment2');
    insert into test3 values( 'EFG123',25,75,'comment3');
    insert into test3 values( 'EFG123',25,75,'comment4');
    insert into test3 values( 'EFG123',25,75,'comment5');
    insert into test3 values( 'XYZ123',1,10,'comment6');
    insert into test3 values( 'XYZ123',2,15,'comment7');
    commit;
    
    select * from test3;
    
    PART_TYPE_ID           GROUP_ID PART_DESC_ID PART_CMT
    -------------------- ---------- ------------ --------------------
    ABC123                        1           10 comment1
    ABC123                        1           10 comment2
    ABC123                        2           15 comment1
    ABC123                        2           15 comment2
    EDG123                        25          75 comment3
    EDG123                        25          75 comment4
    EDG123                        25          75 comment5
    XYZ123                        1           10 comment6
    XYZ123                        2           15 comment7
    
    9 rows selected.
    
    Desired output:
    
    PART_TYPE_ID           GROUP_ID PART_DESC_ID PART_CMT
    -------------------- ---------- ------------ --------------------
    ABC123                        1           10 comment1 
    ABC123                        2           15 comment1
    XYZ123                        1           10 comment1
    XYZ123                        2           15 comment2
    
    RULE: where one part_type_id has multiple (2 or more distinct combinations) of group_id/part_desc_id
    
    NOTE: There are about 12 columns in the table, for brevity I only included 4.
    
    
    
    

    Post edited by: orclrunner was updated desired output and rule

    Hello

    Here's one way:

    WITH got_d_count AS

    (

    SELECT part_type_id, group_id, part_desc_id

    MIN (part_cmt) AS min_part_cmt

    COUNT AS d_count (*) OVER (PARTITION BY part_type_id)

    OF test3

    GROUP BY part_type_id, group_id, part_desc_id

    )

    SELECT DISTINCT

    group_id, part_desc_id, part_type_id, min_part_cmt

    OF got_d_count

    WHERE d_count > 1

    ;

    Output:

    GROUP_ID PART_DESC_ID MIN_PART_CMT PART_TYPE_ID

    ------------ ---------- ------------ ------------

    ABC123 1 10 comment1

    ABC123 2 15 comment1

    XYZ123 1 10 comment6

    XYZ123 2 15 comment7

    Analytical functions, such as the COUNTY and MIN, many global versions, in addition, it can give the same results.  Use the analytical versions when each row of output corresponds to exactly 1 row of input and the aggregate and GROUP BY version when each line of output corresponds to a group of lines 1 or more input.  In this issue, each line of output appears to be a group of input lines having the same group_id, part_type_id, and part_desc_id (I'm guessing just, this only has never stated), so I used GROUP BY to get 1 row of output for every input lines.

  • Truncate output of analytical function?

    For example this query:

    Select month, sum (tot_sales) monthly_sales,.

    AVG (Sum (tot_sales)) (any order by month

    between 1 above and 1 below) rolling_avg

    orders

    where year = 2001 and region_id = 6

    Group by month;

    gives me an output which includes several decimal places for the rolling_avg column.

    Is there a way to truncate this? I tried to use the rounded outside the analytical function and surely enough, it didn't work. I can't think otherwise.

    You can use an external selection on the result of this query

    select trunc(rolling_avg) from
    ( rolling_avg query);
    

Maybe you are looking for

  • Satellite Pro P200-15W: after Bios Update 1.90 incredibly noisy fan

    Hi, I have a Toshiba Satellite Pro P200-15W, I recently made an update to BIOS version 1.9 and seems to have been a big mistake.After restarting the computer, I had a lot of software deconfig and the fan has become incredibly noisy. I have the proble

  • Pavilion v042tx: is - anyone know which port of the screen if I want to change my LCD?

    I want to change my LCD v042tx because it has a pixel dead for a long time, but I don't know which port it is. can you tell me how much is it?

  • STOP: 0 × 0000007 b on Vista

    I get this error when I try to boot Vista after a new installation. (I tried Vista Home Premium and Ultimate from Vista. The Xp version of this error says it is inccessible boot drive. Is it the same for Vista? I tried to start with a single hard dri

  • HP Pavilion Notebook PC shuts down without warning

    Hello I've had my HP Pavilion g6-2230sa Notebook PC for over a year now, and just recently, it began to die without any warning when it gets to 30-40% battery. Before today, he used to tell me when he reached 11%, so I had time to save everything, bu

  • Shockwave unlimited with family safety

    I use Family Safety parental controls for my children profiles on our computers. How to allow games that have been downloaded with a Shockwave unlimited account in parental control?