without analytic function

Hello experts.

I have data similar to what follows below

create table t1
(
  id number(30),
  description varchar(4000)


);

insert into t1 values (1, 'zone');
insert into t1 values (2, 'small');


create table t2
(
   id number(30),
   place varchar(4000),
   info varchar(4000)

);

insert into t2 values (1, 'USA', 'Class U');
insert into t2 values (1, 'Mexico', 'Class M');
insert into t2 values (2, 'Germany', 'Class G');

I need help with something similar to what follows below without using any analytic function

Description of the ID info Place

1 box USA class U

Mexico 1 M class

2 small Germany class G

Any help is appreciated. Thank you

Hello

user13328581 wrote:

... I use an older version of oracle. Oracle 7.

Normally, your developers are older than your software.

You should be able to do what you want with a self-join on t2; a copy (d) should be displayed, and the other copy (c) contains all related values you need for comparison.

SELECT t2d.id

DECODE (t2d.place

MAX (t2c.place)

t1.description

) AS description

t2d.place

t2d.info

FROM t1

, t2 t2d - display

t2 t2c - compare

WHERE t1.id = t2d.id

AND t2d.id = t2c.id

GROUP BY t1.description

t2d.id

t2d.place

t2d.info

ORDER BY t2d.id

t2d.place DESC

;

Output:

ID DESCRIPTION PLACE INFO

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

1 box USA class U

Mexico 1 M class

2 small Germany class G

I've tested this in Oracle 11, but it should work in Oracle 7.

If this isn't the case, you may need to create a view.

Tags: Database

Similar Questions

  • Deputy of analytical functions

    Hi all

    I'm writing a query without using the analytical functions.
    Analytical func using,.
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    
    SELECT id, sal, rank() OVER (PARTITION BY ID ORDER BY SAL) rnk FROM 
    (SELECT 10 AS id, 100 AS sal FROM DUAL
        UNION ALL
        SELECT 10, 300 FROM DUAL
        UNION ALL
        SELECT 10, 400 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 300 FROM DUAL
        UNION ALL
        SELECT 30, 100 FROM DUAL
        UNION ALL
        SELECT 40, 100 FROM DUAL
        UNION ALL
        SELECT 40, 200 FROM DUAL
        )
    Expected results. I want that these results without analytical functions.
    10     100     1
    10     300     2
    10     400     3
    20     200     1
    20     200     1
    20     300     3
    30     100     1
    40     100     1
    40     200     2

    Hello

    SamFisher wrote:
    Hi all

    I'm writing a query without using the analytical functions.

    Why? What is the problem with the analytical functions? You have Oracle 11.2. Use it. Do not act as you have Oracle 8.0.

    One way to do that is a scalar subquery:

    SELECT    id
    ,       sal
    ,       (
              SELECT  1 + COUNT (*)
              FROM    table_x
              WHERE   id          = x.id
              AND     sal     < x.sal
           )     AS rnk
    FROM      table_x  x
    ORDER BY  id
    ,            rnk
    ;
    

    But it is extremely inefficient. This is an example of textbood (perhaps literally) why RANK is so useful.

  • Nth salary using the analytic function

    I use under function to calculate second highest with empno and deptno salary.

    Is it possible to get the same result with another query without using Assembly only analytical functions condition.using and windows function is possible to get the desired output?

    SELECT e.empno,

    e.DEPTNO,

    tmp. SAL as second_higher_salary

    FROM emp e,.

    (SELECT Empno,

    DEPTNO,

    SAL,

    DENSE_RANK() (PARTITION BY deptno ORDER of sal) AS rnk

    WCP

    ) tmp

    WHERE tmp.deptno = e.deptno

    and tmp.rnk = 2

    EMPNO DEPTNO SAL

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

    7934 10 2450

    7782 10 2450

    7839 10 2450

    7876 20 1100

    7369 20 1100

    7902 20 1100

    7788 20 1100

    7566 20 1100

    7900 30 1250

    7844 30 1250

    7654 30 1250

    7521 30 1250

    7499 30 1250

    7698 30 1250

    7900 30 1250

    7844 30 1250

    7654 30 1250

    7521 30 1250

    7499 30 1250

    7698 30 1250

    Here's my solution:

    Select empno,

    DEPTNO,

    FIRST_VALUE (sal) (PARTITION BY deptno ORDER by sal desc)

    de)

    SELECT EmpNo,

    DEPTNO,

    Decode (DENSE_RANK () OVER (PARTITION BY deptno order by sal desc), 1,-sal, sal) sal

    WCP

    )

    /

    EMPNO DEPTNO FIRST_VALUE (SAL) OVER (PARTITIONBYDEPTNOORDERBYSALDESC)

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

      7782 10 2450
      7934 10 2450
      7839 10 2450
      7566 20 2975
      7876 20 2975
      7369 20 2975
      7788 20 2975
      7902 20 2975
      7499 30 1600
      7844 30 1600
      7654 30 1600
      7521 30 1600
      7900 30 1600
      7698 30 1600
  • Purpose of the ORDER BY clause in the analytic function Min Max

    I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.

    user10566312 wrote:
    I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.

    It is a good point that many developers are not so aware. As far as I understand it the way it works.

    Some analytical functions do not need an order by or windowing clause (SUM, COUNT, MIN, etc.). If there is no specified window, then the full score is the window.
    As soon as you add a command also add you a windowing clause. This window has the default value of 'rank ofrows between unbounded preceding and current_row. So as soon as you add an order by clause, you get a sliding window.

    Documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm

    windowing_clause
    ...
    You cannot specify this clause unless you specified the order_by_clause. Window limits defined by the clause RANGE you can not specify only a single expression to the > order_by_clause. Please refer to 'Restrictions on the ORDER BY Clause'.

    example of

    with testdata as (select 10 numval, level lv from dual connect by level < 10)
    select lv, numval, sum(numval) over () sum1, sum(numval) over (order by lv) sum2
    from testdata;
    
    LV NUMVAL SUM1 SUM2
    -- ------ ---- ----
     1     10   90   10
     2     10   90   20
     3     10   90   30
     4     10   90   40
     5     10   90   50
     6     10   90   60
     7     10   90   70
     8     10   90   80
     9     10   90   90 
    

    Published by: Sven w. on 25 Sep 2012 16:57 - default behavior has been corrected. Thanks to Chris

  • Problem with analytical function for date

    Hi all

    ORCL worm:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production."
    AMT for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    I have a problem with the analtical for the date function. I'm trying to group records based on timestamp, but I'm failing to do.
    Could you please help me find where I'm missing.
    This is the subquery. No issue with this. I'm just posting it for reference. 
    select sum(disclosed_cost_allocation.to_be_paid_amt) amt,
        substr(reference_data.ref_code,4,10) cd,
        to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp,
        DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id
      FROM Deal.Fee_Mapping_Definition ,
        Deal.Fee_Index_Definition ,
        Deal.Fee_Closing_Cost_Item,
        Deal.Closing_Cost,
        Deal.Document_Generation_Request,
        deal.PRODUCT_REQUEST,
        deal.External_Order_Request,
        deal.External_Order_Status,
        deal. DISCLOSED_CLOSING_COST,
        deal.DISCLOSED_COST_ALLOCATION,
        deal.reference_data
      WHERE Fee_Mapping_Definition.Fee_Code                    = Fee_Index_Definition.Fee_Code
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Fee_Closing_Cost_Item.Fee_Index_Definition_Id
      AND Fee_Closing_Cost_Item.Closing_Cost_Id                = Closing_Cost.Closing_Cost_Id
      AND CLOSING_COST.PRODUCT_REQUEST_ID                      = Document_Generation_Request.Product_Request_Id
      AND closing_cost.product_request_id                      = product_request.product_request_id
      AND Product_Request.Deal_Id                              = External_Order_Request.Deal_Id
      AND external_order_request.external_order_request_id     = external_order_status.external_order_request_id
      AND external_order_request.external_order_request_id     = disclosed_closing_cost.external_order_request_id
      AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID    = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Disclosed_Closing_Cost.Fee_Index_Definition_Id
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id   = Reference_Data.Reference_Data_Id
      AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 )
      AND External_Order_Status.Order_Status_Txt               = ('GenerationCompleted')
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id  IN ( 7789, 7788,7596 )
      AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID          = 1099
      AND Document_Generation_Request.Product_Request_Id      IN
        (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id
        FROM Deal.Disclosed_Cost_Allocation,
          Deal.Disclosed_Closing_Cost,
          DEAL.External_Order_Request,
          DEAL.PRODUCT_REQUEST,
          Deal.Scenario
        WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id
        AND Disclosed_Closing_Cost.External_Order_Request_Id      = External_Order_Request.External_Order_Request_Id
        AND External_Order_Request.Deal_Id                        = Product_Request.Deal_Id
        AND product_request.scenario_id                           = scenario.scenario_id
        AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID                  = 7206
        AND product_request.servicing_loan_acct_num              IS NOT NULL
        AND product_request.servicing_loan_acct_num               = 0017498379
          --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263
        )
      GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID,
        External_Order_Status.Status_Updated_Tmstp,
        Reference_Data.Ref_Code,
        disclosed_cost_allocation.to_be_paid_amt
      order by 3 desc,
        1 DESC;
    
    Result:
    2000     1304-1399     28-JUL-2012 19:49:47     6880959
    312     1302     28-JUL-2012 19:49:47     6880958
    76     1303     28-JUL-2012 19:49:47     6880957
    2000     1304-1399     28-JUL-2012 18:02:16     6880539
    312     1302     28-JUL-2012 18:02:16     6880538
    76     1303     28-JUL-2012 18:02:16     6880537
    
    
    But, when I try to group the timestamp using analytical function,
    
    
    select amt 
            ,cd 
            ,rank() over(partition by tmstp order by tmstp desc) rn 
    from 
    (select sum(disclosed_cost_allocation.to_be_paid_amt) amt,
        substr(reference_data.ref_code,4,10) cd,
        to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp,
        DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id
      FROM Deal.Fee_Mapping_Definition ,
        Deal.Fee_Index_Definition ,
        Deal.Fee_Closing_Cost_Item,
        Deal.Closing_Cost,
        Deal.Document_Generation_Request,
        deal.PRODUCT_REQUEST,
        deal.External_Order_Request,
        deal.External_Order_Status,
        deal. DISCLOSED_CLOSING_COST,
        deal.DISCLOSED_COST_ALLOCATION,
        deal.reference_data
      WHERE Fee_Mapping_Definition.Fee_Code                    = Fee_Index_Definition.Fee_Code
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Fee_Closing_Cost_Item.Fee_Index_Definition_Id
      AND Fee_Closing_Cost_Item.Closing_Cost_Id                = Closing_Cost.Closing_Cost_Id
      AND CLOSING_COST.PRODUCT_REQUEST_ID                      = Document_Generation_Request.Product_Request_Id
      AND closing_cost.product_request_id                      = product_request.product_request_id
      AND Product_Request.Deal_Id                              = External_Order_Request.Deal_Id
      AND external_order_request.external_order_request_id     = external_order_status.external_order_request_id
      AND external_order_request.external_order_request_id     = disclosed_closing_cost.external_order_request_id
      AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID    = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Disclosed_Closing_Cost.Fee_Index_Definition_Id
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id   = Reference_Data.Reference_Data_Id
      AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 )
      AND External_Order_Status.Order_Status_Txt               = ('GenerationCompleted')
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id  IN ( 7789, 7788,7596 )
      AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID          = 1099
      AND Document_Generation_Request.Product_Request_Id      IN
        (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id
        FROM Deal.Disclosed_Cost_Allocation,
          Deal.Disclosed_Closing_Cost,
          DEAL.External_Order_Request,
          DEAL.PRODUCT_REQUEST,
          Deal.Scenario
        WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id
        AND Disclosed_Closing_Cost.External_Order_Request_Id      = External_Order_Request.External_Order_Request_Id
        AND External_Order_Request.Deal_Id                        = Product_Request.Deal_Id
        AND product_request.scenario_id                           = scenario.scenario_id
        AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID                  = 7206
        AND product_request.servicing_loan_acct_num              IS NOT NULL
        AND product_request.servicing_loan_acct_num               = 0017498379
          --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263
        )
      GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID,
        External_Order_Status.Status_Updated_Tmstp,
        Reference_Data.Ref_Code,
        disclosed_cost_allocation.to_be_paid_amt
      order by 3 desc,
        1 DESC);
    
    Result:
    312     1302            1
    2000     1304-1399     1
    76     1303            1
    312     1302            1
    2000     1304-1399     1
    76     1303            1 
    
    
    Required output:
    312     1302            1
    2000     1304-1399     1
    76     1303            1
    312     1302            2
    2000     1304-1399     2
    76     1303            2
    THX
    Rod.

    Hey, Rod,

    My guess is that you want:

    , dense_rank () over (order by  tmstp  desc)  AS rn 
    

    RANK means you'll jump numbers when there is a link. For example, if all 3 rows have the exact same last tmstp, all 3 rows would be assigned number 1, GRADE would assign 4 to the next line, but DENSE_RANK attributes 2.

    "PARTITION x" means that you are looking for a separate series of numbers (starting with 1) for each value of x. If you want just a series of numbers for the entire result set, then do not use a PARTITION BY clause at all. (PARTITION BY is never required.)
    Maybe you want to PARTITIONNER IN cd. I can't do it without some examples of data, as well as an explanation of why you want the results of these data.
    You certainly don't want to PARTITION you BY the same expression ORDER BY; It simply means that all the lines are tied for #1.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Simplify the problem as much as possible.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

    Published by: Frank Kulash, August 1, 2012 13:20

  • get a single result with analytical functions

    SELECT delrazjn. TYPE, delrazjn. DATE, delrazjn. USER, delrazjn. The IID OF the ZKET_DR delraz, ZKET_DR_JN delrazjn
    WHERE delraz. IID = delrazjn. IID
    AND (delrazjn. TYPE = 'UP2' GOLD delrazjn. TYPE = 'An increase in 1') AND delrazjn. IID_N IS NOT NULL

    This is an example of my sql. But there is more than one result of delrazjn. IID. How can I get the first enterd in DB and ignore others, there will only be one result and no more.
    The first result came in, that I can see for delrazjn. DATE.

    I try to do that with analytical functions, but without success.

    You're right, I told you that I can't test the code.

    I hope this works now:

    SELECT delrazjn.TYPE, delrazjn.DATE, delrazjn.USER, delrazjn.IID
    FROM ZKET_DR delraz, ZKET_DR_JN delrazjn
    WHERE delraz.IID = delrazjn.IID
    AND (delrazjn.TYPE = 'UP2' OR delrazjn.TYPE = 'UP1') AND delrazjn.IID_N IS NOT NULL
    and delrazjn.date=(select min(d.date) from ZKET_DR_JN d where d.type=delrazjn.type and d.user=delrazjn.user)
    
  • sensitive analytical function

    Hi all

    I am new to Oracle analytical functions, and I'll try to find the best way to write my query.

    What follows is a simplified version of a table, I work with...
    CREATE TABLE my_table
    (
        pid          NUMBER  NOT NULL,
        my_value     NUMBER,
        value_date   DATE    NOT NULL,
    
        CONSTRAINT pk_my_table PRIMARY KEY (pid, value_date)
    );
    Note that 'value_date' is part of the primary key.

    Each "pid", I would like to request to view 5 columns:
    1. The NEST
    2. the max value of "my_value" for the most recent 7 days of data
    3. the day correspondent (value_date) for the day 7 max
    4. the max value of "my_value" for the last 30 days of data
    5. the day (value_date) for the maximum of 30 days

    Is it possible to do without a join? What is the best way to achieve this?

    Thanks in advance for any help,

    Kal

    With the following test data:

    SQL> select * from my_table;
    
           PID   MY_VALUE VALUE_DAT
    ---------- ---------- ---------
             1        300 18-FEB-10
             1        200 17-FEB-10
             1       4500 16-FEB-10
             1        800 15-FEB-10
             1      12000 14-FEB-10
             1      21000 13-FEB-10
             1       5600 12-FEB-10
             1      18400 11-FEB-10
             1       7200 10-FEB-10
             1      24000 09-FEB-10
             1       8800 08-FEB-10
             1       6000 07-FEB-10
             1      44200 06-FEB-10
             1       2800 05-FEB-10
             1      58500 04-FEB-10
             1       8000 03-FEB-10
             1      30600 02-FEB-10
             1       7200 01-FEB-10
             1      62700 31-GEN-10
             1      48000 30-GEN-10
             1      16800 29-GEN-10
             1      83600 28-GEN-10
             1      18400 27-GEN-10
             1      16800 26-GEN-10
             1      40000 25-GEN-10
             1      23400 24-GEN-10
             1      99900 23-GEN-10
             1      67200 22-GEN-10
             1       5800 21-GEN-10
             1      57000 20-GEN-10
             1      96100 19-GEN-10
             1      64000 18-GEN-10
             1      52800 17-GEN-10
             1      71400 16-GEN-10
             1      14000 15-GEN-10
             1       7200 14-GEN-10
             1     111000 13-GEN-10
             1      64600 12-GEN-10
             1     113100 11-GEN-10
             1      84000 10-GEN-10
             2       6000 18-FEB-10
             2       7800 17-FEB-10
             2      13500 16-FEB-10
             2      25600 15-FEB-10
             2     276000 14-FEB-10
             2     210000 13-FEB-10
             2     162400 12-FEB-10
             2      36800 11-FEB-10
             2      86400 10-FEB-10
             2     480000 09-FEB-10
             2       8800 08-FEB-10
             2     102000 07-FEB-10
             2    1237600 06-FEB-10
             2      61600 05-FEB-10
             2    1287000 04-FEB-10
             2     144000 03-FEB-10
             2     275400 02-FEB-10
             2      93600 01-FEB-10
             2    1630200 31-GEN-10
             2    1248000 30-GEN-10
             2     235200 29-GEN-10
             2    3176800 28-GEN-10
             2      73600 27-GEN-10
             2     403200 26-GEN-10
             2     200000 25-GEN-10
             2     280800 24-GEN-10
             2     599400 23-GEN-10
             2    1612800 22-GEN-10
             2     110200 21-GEN-10
             2    1653000 20-GEN-10
             2    2498600 19-GEN-10
             2    2368000 18-GEN-10
             2     211200 17-GEN-10
             2    2570400 16-GEN-10
             2     224000 15-GEN-10
             2     223200 14-GEN-10
             2     999000 13-GEN-10
             2    2325600 12-GEN-10
             2    1017900 11-GEN-10
             2    2352000 10-GEN-10
    
    Selezionate 80 righe.
    

    Check this query:

    SQL> select pid
      2         ,max(case WHEN value_date>trunc(sysdate)-7 THEN my_value ELSE 0 END) MAX_7_days
      3         ,max(value_date) KEEP (dense_rank first order by (case WHEN value_date>trunc(sysdate)-7 THEN my_value ELSE 0 END) desc) DAY_7_DAYS
      4         ,max(case WHEN value_date>trunc(sysdate)-30 THEN my_value ELSE 0 END) MAX_30_DAYS
      5         ,max(value_date) KEEP (dense_rank first order by case WHEN value_date>trunc(sysdate)-30 THEN my_value ELSE 0 END desc) DAY_30_DAYS
      6    from my_table
      7  group by pid;
    
           PID MAX_7_DAYS DAY_7_DAY MAX_30_DAYS DAY_30_DA
    ---------- ---------- --------- ----------- ---------
             1      21000 13-FEB-10       99900 23-GEN-10
             2     276000 14-FEB-10     3176800 28-GEN-10
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 18, 2010 21:03

  • any analytic function or any other function of last time stamp?

    Hello gurus,

    do you have an idea of the analytical function or any other function that gets me the last time stamp?


    say I have data like this
      login_time                                     login_id           name
       2/11/2010 11:08:32  AM                 A123            Frank
       2/11/2010  2:33:59  PM                  A123            fRANK
       2/11/2010  6:10:45  PM                  A123            Frank
       2/10/2010 8:12:25  AM                   B369            morgon
       2/10/2010 6:10:27  PM                   B369            Morgon
    
      
    so now, I want to get the latest connection time...
    well in frank case would be 2/11/2010 6:10:45 PM
    
      in morgon case would be  2/10/2010 6:10:27 PM
     
    Any idea gurus?

    Analytical MAX (without band) extracted a line for each connection, add a SEPARATE for separate lines:

    SELECT    UPPER (name)      AS u_name, MAX (login_time) over (partition by UPPER (name)) AS last_login_time
    FROM      table_x
    

    ROW_NUMBER analytic to get just one line for each user:

    SELECT u_name, login_time from (
    SELECT    UPPER (name)      AS u_name, login_time, ROW_NUMBER() over (partition by UPPER (name) ORDER BY login_time desc) rn
    FROM      table_x
    )
    where rn=1
    

    Max
    http://oracleitalia.WordPress.com

  • How to use Group by in the analytic function

    I need to write the Department that has the minimum wage in a row. She must be with analytical function, but I have problem in group by. I can't use min() without group by.

    Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) < 20 WHERE RN order by deptno;

    Published by: senza on 6.11.2009 16:09

    Hello

    senza wrote:
    I need to write the Department that has the minimum wage in a row. She must be with analytic function

    Therefore with an analytic function? Looks like it is a duty.

    The best way to get these results is with an aggregate, not analysis, function:

    SELECT      MIN (deptno) KEEP (DENSE_RANK FIRST ORDER BY sal)     AS dept_with_lowest_sal
    FROM      scott.emp
    ;
    

    Note that you do not need a subquery.
    This can be modififed if, for example, you want the lowest Department with the sal for each job.

    But if your mission is to use an analytical function, that's what you have to do.

    but I have problem in group by. I can't use min() without group by.

    Of course, you can use MIN without GROUP BY. Almost all of the aggregate (including MIN) functions have analytical equivalents.
    However, in this issue, you don't need to. The best analytical approach RANK only, not use MIN. If you ORDER BY sal, the lines with rank = 1 will have the minimum wage.

    Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) WHERE the RN< 20="" order="" by="">

    Try to select plain old sal instead of MIN (sal) and get reid of the GROUP BY clause.

    Add ROWNUM in the ORDER BY clause is to make RANK return the same result as ROW_NUMBER, every time that it is a tie for the sal, the output will still be distinct numbers. which line gets the lower number will be quite arbitrary, and not necessarily the same every time you run the query. For example, MARTIN and WARD have exactly the same salary, 1250. The query you posted would assign rn = 4 to one of them and rn = 5 to another. Who gets 4? It's a toss-up. It could be MARTIN the first time you try, and WARD the next. (In fact, in a very small table like scott.emp, it probably will be consistent, but always arbitrary.) If this is what you want, it would be clearer and simpler just to use ROW_NUMEBR instead of RANK.

  • More help with analytical functions

    I had great hellp here yesterday and I need once more today. I guess I'm still not able to get a solid understanding of analytical functions. So here's the problem:
    table with 3 collars:
    product_id (int), sale_date (to date), count_sold (int) - each file show that the number of items have been sold for the product at a given date.
    The query should return the 3 passes of the table AND a fourth column that contains the date with the best sales of the product. If there are two or more dates with equal sales, the last being is chosen.

    Is this possible using an analytical function appropriately and without using a subquery?

    example:
    product_id, sale_date, count_sold, high_sales_date
    1, 01-01-2008, 10, 05/10/2008,.
    1, 2008-03-10, 20, 10/05/2008
    1, 10/04/2008, 25, 05/10/2008
    1, 10/05/2008, 25, 05/10/2008
    1, 01/06/2008, 22, 05/10/2008
    2, 05/12/2008, 12, 05/12/2008
    2, 06/01/2009, 10, 05/12/2008

    Thank you

    Hello

    Try this:

    SELECT     product_id
    ,     sale_date
    ,     count_sold
    ,     FIRST_VALUE (sale_date) OVER ( PARTITION BY  product_id
                                   ORDER BY          count_sold          DESC
                               ,               sale_date          DESC
                             )      AS high_sales_date
    FROM     table_x;
    

    If you would post INSERT statements for your data, then I could test it.

    Focus issue: Why use FIRST_VALUE with descending order and not LAST_VALUE (ASCending) ORDER of default?

  • Report Builder 6i do not recognize the analytical functions

    Hi all, in an attempt to speed up a slow query, I applied the analytical function to it. I can save the query in the generator without any problem, however, I can't create data between this request and other links. After I have comment on the analytical function, data bindings can be made. My colleague says Report Builder 6i is too old so he can recognize only the ANSI SQL syntax. Since our server DB uses Oracle 10 g 2, is there a way for the generator of reports to identify and compile syntax of Oracle 10 g?

    Thank you very much.

    Hello

    Your colleague is right. Even if the SQL query is executed by the DB server, reports must analyze the SQL query.

    The SQL parser included in reports 6i-based 8.0.6

    You can see this version using the report designer:

    Menu: Help-> on Report Builder...

    ORACLE Server Release 8.0.6.0.0

    Concerning

  • Satellite U920T - 10G - touch screen without any function

    Hello together,

    I have been using the nice nice feature now for a few weeks and start to have trouble with him.

    I have the problem that randomly touch screen without any function, I can touch the screen
    but I want to, but without any reaction.

    It starts just besides the requests or anything before, I just browsing in the web site and a second to another.

    If I restart the PC, everything works normally again, I still using the drivers that have been pre-installed and have no changes for the drivers so far.

    Any suggestions, what could cause this problem?

    Kind regards

    Hello

    In my opinion, a process that controls the touch screen hangs or does not answer more and as a result, you can not touch works.

    Recommend reinstalling the driver of Toshiba + Toshiba UE driver page system.
    If this is not enough to try the system recovery and test the device with factory settings.

  • 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.

Maybe you are looking for

  • I have no URL bar, bar of tools or 'file' / 'see' etc. Where are they?

    Everything has gone so that now I have firefox page and can't navigate! Can't navigate even to click on the email confirmation for this site!

  • Need router WLan for the Satellite L300D PSLC0E

    l want to buy a wireless router for this model L300D PSC0E OS Vistahave Virgin broadband with a modem webstar. l want to do things first and don't want to go back and forwords to the shop like l'm in a wheelchair. Thanks much for any help.Regads to a

  • Satellite L650-14F - maximum temperature of the CPU

    Hello guys and sorry for my language. Can you tell me what is the optimum temperature for this laptop and what is the maximum temperature?Thank you

  • Chapter not appearing markers do not

    If for any reason any my new 4th Gen Apple TV does not seem to recognize chapter markers on the videos that I encoded in Handbrake. If I open the file with Quicktime chapters show. On my 3rd generation and 2nd Gen Apple TV, they both show upward. But

  • Lollipop for Yoga compressed 2 Pro when?

    I read that the Loli is out for the Yoga 2, but not the Pro aparently. I had updates. Is there a release date? EDIT 22/07/15: online edition of object for research opportunities. Amy_Lenovo