best way to find the maximum value that is less than a specific value?

Hello guys,.

What is the fastest way to find a record that has value max of a field and there is a limitation to a specific value for ex:

example 1:
create table dummy(master_id number, detail_id number, some_value varchar2(80));
 
insert into dummy values (1,1,'bla bla1');
insert into dummy values (1,2,'bla bla2');
insert into dummy values (1,3,'bla bla3');
insert into dummy values (2,1,'bla bla4');
insert into dummy values (2,2,'bla bla5');
insert into dummy values (2,3,'bla bla6');
insert into dummy values (2,4,'bla bla7');
commit;
I want to get:
1 3 bla bla3
2 4 bla bla7
And these applications give a correct result:
Select * 
from   dummy d1
where  detail_id = (select max(detail_id) from dummy d2 where d2.master_id = d1.master_id);
 
OR next one which i prefered.
 
Select *
From   (Select d1.* , row_number() over(partition by master_id order by detail_id desc) r
        from   dummy d1)
Where  r = 1;
If these solutions are enough or is there a better way?

Edited by: elcaro on 13.Ara.2011 04:02

Edited by: elcaro on 14.Ara.2011 04:31

Please try this with your new test tables:

select m.master_id,
       m.master_data,
       max(d.id) keep (dense_rank last order by data_value, d.id) d_id,
       max(d.master_id)  keep (dense_rank last order by data_value, d.id) d_master_id,
       max(data_value) keep (dense_rank last order by data_value, d.id) d_data_value,
       max(date_data)  keep (dense_rank last order by data_value, d.id) d_date_data
from master_dummy m, detail_dummy d
where m.master_id=d.master_id
and d.date_data <= to_timestamp('04012010','ddmmyyyy')
group by m.master_id, m.master_data

Published by: hm on 14.12.2011 05:18

(I added d.id column in the order by the dense_rank. clause that could make a difference when there is more than one line with the same data_value).

Tags: Database

Similar Questions

  • Is it possible to connect a simple 1 d array to a digital indicator or what would be the best way to display the numeric values of the array on the front panel?

    Is it possible to connect a simple 1 d array to a digital indicator or what would be the best way to display the numeric values of the array on the front panel? Examples or suggestions would be greatly appreciated.

    Thank you

    Tunis

    Thank you Adam, it's originally in a while loop, I placed it in a loop for example, wired County in the for loop and presto, this son of a digital indicator. It works very well. Thanks for the help folks.

  • [10g] way to find the least value greater than a value?

    I have a simple (I think) question...

    Part 1:
    Is there a way to determine the least value among a set of values, which is greater than 0?

    A few examples:
    Set of values:
    {0,1,2,3}
    Return value:
    1
    
    Set of values:
    {0,5,10,20,100}
    Return value:
    5
    
    Set of values:
    {1,4,9,11}
    Return value:
    1
    Part 2:
    Same thing, but greater than some given value, 0 is not necessary.
    Set of values:
    {0,1,2,3}
    Parameter value: 
    2
    Return value:
    3
    
    Set of values:
    {0,5,10,20,100}
    Parameter value: 
    2
    Return value:
    5
    
    Set of values:
    {1,4,9,11}
    Parameter value: 
    2
    Return value:
    4
    In particular, I'm looking for an effective way to achieve this. I think I can do it with a set of CASE statements, but it becomes really complex values compare more than you.

    My first thought was to use the function LESS, but which does not allow me a way to use a parameter.

    Any suggestions?

    Hello

    Thanks for posting the sample data.
    I know that it takes hard work to do, but it's really help people who want to help you. Sometimes, it can help you, too, giving you new perspectives on what the problem really is. As often do not, when I am confused by something and need help, I discovered an answer while assembling a test script and write a description of the problem.

    You can use the function LESS, with CASE expressions as arguments, to do what you want:

    SELECT     ord_nbr
    ,     seq_nbr
    ,     time_spent /
         CASE
              WHEN     comp_qty > plan_qty
              THEN     LEAST ( CASE  WHEN ord_qty - scrap_qty > 0 THEN ord_qty - scrap_qty ELSE 1E99 END
                         , CASE  WHEN plan_qty              > 0 THEN plan_qty           ELSE 1E99 END
                         , CASE  WHEN comp_qty            > 0 THEN comp_qty         ELSE 1E99 END
                         )
         END     AS unit_time
    FROM     ord_detail
    ;
    

    This means that your actual data are never as large as 1E99, and at least one of the three expressions will be greater than 0.
    If or any of these assumptions are false, I'm sure we can find a solution, but it will probably be even messier.

    It should work in Oracle 8.1.

  • How to find the maximum value in a collection

    Hi all

    I'm using Oracle 11 g 2. I need to know the maximum value in a collection of items.

    When I run the following, I get the maximum number of collection as '5' but I need the max value itself which is 8, please help.


    DECLARE
    type v_number1 is table of number of directory indexes;

    v_number v_number1;

    IDX NUMBER.
    psrc_file VARCHAR2 (10): = '1,2,4,8,6';
    v_src_file_string_array v_number1;
    number of max_temp;

    BEGIN

    SELECT regexp_substr (psrc_file, "[^,] +', 1, level") coll
    LOOSE COLLECTION v_src_file_string_array
    FROM (SELECT psrc_file FROM dual)
    CONNECTION OF LEVEL < = length (regexp_replace (psrc_file, "[^,] +")) + 1;

    -Set up some test values:
    BECAUSE me IN v_src_file_string_array. FIRST... v_src_file_string_array. COUNTING LOOP
    -v_numbers (i): = v_src_file_string_array (i);
    v_number (i): = i;
    END LOOP;

    max_temp: = v_number (v_number.first);
    IDX: = v_number.first;

    -Display the contents of the table:
    While the idx is not null
    loop
    If (idx) v_number > = max_temp
    then
    max_temp: = v_number (idx);
    end if;

    IDX: = v_number.next (idx);
    end loop;

    dbms_output.put_line ('Max: ' | max_temp);
    end;
    /


    Thank you!

    Harinath Arasu says:
    Hi all

    I'm using Oracle 11 g 2. I need to know the maximum value in a collection of items.

    When I run the following, I get the maximum number of collection as '5' but I need the max value itself which is 8, please help.

    DECLARE
    type v_number1 is table of number of directory indexes;

    v_number v_number1;

    IDX NUMBER.
    psrc_file VARCHAR2 (10): = '1,2,4,8,6';
    v_src_file_string_array v_number1;
    number of max_temp;

    BEGIN

    SELECT regexp_substr (psrc_file, "[^,] +', 1, level") coll
    LOOSE COLLECTION v_src_file_string_array
    FROM (SELECT psrc_file FROM dual)
    CONNECT BY LEVEL<= length(regexp_replace(psrc_file,="" '[^,]+'))="" +="">

    -Set up some test values:
    BECAUSE me IN v_src_file_string_array. FIRST... v_src_file_string_array. COUNTING LOOP

    It should be-online 1... v_src_file_string_array. COUNTY

    -v_numbers (i): = v_src_file_string_array (i);
    v_number (i): = i;

    This should be-online v_numbers (i): = v_src_file_string_array (i);

    Can't do you all just...

    DECLARE
         type v_number1 is table of number index by binary_integer;
         v_number v_number1;
         idx NUMBER;
         psrc_file VARCHAR2(10) := '1,2,4,8,6';
         v_src_file_string_array v_number1;
         max_temp number;
    BEGIN
         SELECT regexp_substr(psrc_file, '[^,]+', 1, level) coll
         BULK COLLECT INTO v_src_file_string_array
         FROM (SELECT psrc_file FROM dual)
         CONNECT BY LEVEL <= length(regexp_replace(psrc_file, '[^,]+')) + 1;
    
         FOR i IN 1..v_src_file_string_array.COUNT LOOP
           if max_temp is null or
                    v_src_file_string_array(i) > max_temp then
                max_temp := v_src_file_string_array(i);
              end if;
         END LOOP;
         dbms_output.put_line ('Max: ' || max_temp);
    end;
    

    Or more simply...

    DECLARE
         type v_number1 is table of number index by binary_integer;
         v_number v_number1;
         idx NUMBER;
         psrc_file VARCHAR2(10) := '1,2,4,8,6';
         v_src_file_string_array v_number1;
         max_temp number;
    BEGIN
             SELECT to_number(regexp_substr(psrc_file, '[^,]+', 1, level))
          BULK COLLECT INTO v_src_file_string_array
             FROM (SELECT psrc_file FROM dual)
                  CONNECT BY LEVEL <= length(regexp_replace(psrc_file, '[^,]+')) + 1
             order by 1 desc;
         dbms_output.put_line ('Max: ' || v_src_file_string_array(1));
    end;
    

    Published by: JAC on April 3, 2013 18:56
    Unhandled exception...

  • [8i] best way to replace the 'similar' value values...?

    Some examples of data:

    Sorry for the large / complex set of sample data, but there should be no need to go through it in detail =).

    2 things to keep in mind:
    (1) it is a 8i db
    (2) I can't create any tables in the db, if I can create views
    CREATE TABLE     ord_master
    (     part_nbr          CHAR(25)
    ,     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     ord_type          CHAR(2)
    ,     ord_stat          CHAR(2)
    ,     date_closed     DATE
    );
    
    -- please note, though none of the columns in ord_master are explicitly defined as NOT NULL, 
    -- none of them are NULL in the db, and given how things are input into the table, I don't 
    -- even think it's possible
    
    -- a unique order is described by ord_nbr, sub_ord_nbr.  there should only be one record in
    -- this table for a given unique combination of those columns, though they are not the p.k.
    
    -- NOTE: dates default to 12/31/1900, so in the table above, if an order is still open (thus, 
    -- not closed), it's date_closed will be 12/31/1900.  It will only change once the order closes.
    
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','1','AA','CL',TO_DATE('05/01/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','2','AA','CL',TO_DATE('9/14/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','2','1','AA','CL',TO_DATE('12/03/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','3','1','AA','OP',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','4','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('XYZ-123','5','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    
    
    CREATE TABLE     op_detail
    (     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     major_seq_nbr     CHAR(4)
    ,     wctr_id          CHAR(5)
    ,     oper_stat          CHAR(2)
    ,     plan_su_rsrc     NUMBER(5,2)
    ,     plan_run_rsrc     NUMBER(11,8)
    ,     plan_subc_amt     NUMBER(15,5)
    ,     act_su_rsrc     NUMBER(5,2)
    ,     act_run_rsrc     NUMBER(7,2)
    ,     act_subc_amt     NUMBER(15,2)
    ,     act_start_dt     DATE
    ,     dt_completed     DATE
    ,     qty_planned     NUMBER(13,4)
    ,     qty_recvd          NUMBER(13,4)
    ,     qty_complete     NUMBER(13,4)
    ,     qty_scrap          NUMBER(13,4)
    ,     qty_on_hold     NUMBER(13,4)
    );
              
    -- similar to ord_master, thought none of the columns are explicitly defined as NOT NULL, 
    -- none of the records have NULL values for any of these columns, and I don't think it's 
    -- really possible with the way the system is
    
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0081', 'X516 ', 'CP', 0, 0, 0, 0, .2, 0, TO_DATE('02/03/2010', 'mm/dd/yyyy'), TO_DATE('02/03/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .87, 0, TO_DATE('04/06/2010', 'mm/dd/yyyy'), TO_DATE('04/06/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 159, TO_DATE('03/05/2010', 'mm/dd/yyyy'), TO_DATE('03/05/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0130', 'H211 ', 'CP', .5, .1, 0, .08, .63, 0, TO_DATE('02/10/2010', 'mm/dd/yyyy'), TO_DATE('02/10/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0120', 'H214 ', 'CP', .3, .05, 0, 0, .68, 0, TO_DATE('05/22/2009', 'mm/dd/yyyy'), TO_DATE('05/22/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0122', 'T203 ', 'CP', 2.5, 1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0130', 'H211 ', 'CL', .5, .1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 153.12, TO_DATE('06/10/2009', 'mm/dd/yyyy'), TO_DATE('06/10/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .08, 0, TO_DATE('06/17/2009', 'mm/dd/yyyy'), TO_DATE('06/17/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0081', 'X516 ', 'CL', 0, 0, 0, 0, 0, 0, TO_DATE('07/20/2009', 'mm/dd/yyyy'), TO_DATE('07/20/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, 3.03, 0, TO_DATE('09/11/2009', 'mm/dd/yyyy'), TO_DATE('09/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 204.16, TO_DATE('08/11/2009', 'mm/dd/yyyy'), TO_DATE('08/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0130', 'H211 ','CP', .5, .1, 0, 1.97, 2.67, 0, TO_DATE('07/28/2009', 'mm/dd/yyyy'), TO_DATE('07/29/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 255.2, TO_DATE('11/06/2009', 'mm/dd/yyyy'), TO_DATE('11/06/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0130', 'H212 ', 'CP', .5, .1, 0, .6, .03, 0, TO_DATE('10/21/2009', 'mm/dd/yyyy'), TO_DATE('10/21/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0550', 'R501 ', 'WK', 1, 16, 0, 2.2, 12.4, 0, TO_DATE('05/19/2010', 'mm/dd/yyyy'), TO_DATE('12/31/1900', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, .07, 0, TO_DATE('02/04/2010', 'mm/dd/yyyy'), TO_DATE('02/04/2010', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('4', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .59, 0, TO_DATE('02/06/2004', 'mm/dd/yyyy'), TO_DATE('02/06/2004', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    This is the query, I'm working with right now:
    SELECT     o.part_nbr               
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
    ,          AVG(s.plan_su_rsrc)          AS avg_plan_setup
    ,          MAX(s.plan_su_rsrc)          AS max_plan_setup
    ,          STDDEV(s.plan_su_rsrc)     AS sdev_plan_setup
    ,          MIN(s.plan_run_rsrc)     AS min_plan_run
    ,          AVG(s.plan_run_rsrc)     AS avg_plan_run
    ,          MAX(s.plan_run_rsrc)     AS max_plan_run
    ,          STDDEV(s.plan_run_rsrc)     AS sdev_plan_run
    ,          MIN(s.plan_subc_amt)     AS min_plan_subc
    ,          AVG(s.plan_subc_amt)     AS avg_plan_subc
    ,          MAX(s.plan_subc_amt)     AS max_plan_subc
    ,          STDDEV(s.plan_subc_amt)     AS sdev_plan_subc
    ,          MIN(s.act_su_rsrc)          AS min_act_setup
    ,          AVG(s.act_su_rsrc)          AS avg_act_setup
    ,          MAX(s.act_su_rsrc)          AS max_act_setup
    ,          STDDEV(s.act_su_rsrc)     AS sdev_act_setup
    ,          MIN(s.act_run_rsrc)          AS min_act_run
    ,          AVG(s.act_run_rsrc)          AS avg_act_run
    ,          MAX(s.act_run_rsrc)          AS max_act_run
    ,          STDDEV(s.act_run_rsrc)     AS sdev_act_run
    ,          MIN(s.act_subc_amt)          AS min_act_subc
    ,          AVG(s.act_subc_amt)          AS avg_act_subc
    ,          MAX(s.act_subc_amt)          AS max_act_subc
    ,          STDDEV(s.act_subc_amt)     AS sdev_act_subc     
    ,          MIN(s.act_start_dt)          AS min_start
    ,          MAX(s.act_start_dt)          AS max_start
    ,          MIN(s.dt_completed)          AS min_comp
    ,          MAX(s.dt_completed)          AS max_comp
    ,          MIN(s.qty_planned)          AS min_qty_plan
    ,          AVG(s.qty_planned)          AS avg_qty_plan
    ,          MAX(s.qty_planned)          AS max_qty_plan
    ,          STDDEV(s.qty_planned)     AS sdev_qty_plan
    ,          MIN(s.qty_recvd)          AS min_qty_recvd
    ,          AVG(s.qty_recvd)          AS avg_qty_recvd
    ,          MAX(s.qty_recvd)          AS max_qty_recvd
    ,          STDDEV(s.qty_recvd)          AS sdev_qty_recvd
    ,          MIN(s.qty_complete)          AS min_qty_comp
    ,          AVG(s.qty_complete)          AS avg_qty_comp
    ,          MAX(s.qty_complete)          AS max_qty_comp
    ,          STDDEV(s.qty_complete)     AS sdev_qty_comp
    ,          MIN(s.qty_scrap)          AS min_qty_scrap
    ,          AVG(s.qty_scrap)          AS avg_qty_scrap
    ,          MAX(s.qty_scrap)          AS max_qty_scrap
    ,          STDDEV(s.qty_scrap)          AS sdev_qty_scrap
    ,          MIN(s.qty_on_hold)          AS min_qty_hold
    ,          AVG(s.qty_on_hold)          AS avg_qty_hold
    ,          MAX(s.qty_on_hold)          AS max_qty_hold
    ,          STDDEV(s.qty_on_hold)     AS sdev_qty_hold
    ,          COUNT(*)                    AS rec_cnt
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          (     -- begin in-line view a, to get the min act_start_dt for each order
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ) a     -- end in-line view a          
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbr
    It gives me a lot of descriptive statistics on data stored in the database, divided into groups of the time period.

    I have 7 sets of possible values for the wctr_id column, which are groups of similar/identical positions and should be treated as the same, assuming that the ord_nbr, sub_ord_nbr and major_seq_nbr are the same. In my case statement example above, every time I find 'H211' or 'H212', I'm replacing it with "Z211', which is my new unique identifier for all wctr in the Group ("H211', "H212"). I have 7 of these kinds of groups that should be replaced by a new unique identifier. Is my statement CASE (above) the best way to do it, or is there a better way? These groups of similar-wctr_id are not listed in a table anywhere.

    Hello

    As always, thanks for posting the CREATE TABLE and INSERT statements. It is very useful and leads to the more quickly, better solutions.
    Another thing that is useful and promotes better solutions, faster, is to simplify your problem.
    For example, you need to calculate a large number of aggregates, but looks like you already know how to do this. This issue only affects the CASE expressions, and how they interact with the GROUP BY clause. So just cut most of the aggregate functions.
    Also, it seems that the finer points of view one online have nothing to do with your current problem. For purposes of recognition of this problem, pretend that one is a regular display, so it does not clutter the main request.

    I think your problem might be reformulated as follows:
    You already have a query like this:

    CREATE OR REPLACE VIEW a
    AS
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
    ;
    
    SELECT     o.part_nbr
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
              -- lots of other agtgregates go here in real query
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          a          -- in real query, a is an in-line view
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbr
    ;
    

    which produces this output:

    `                       MIN_
                           PLAN_
    PART_NBR   OP_N WCTR   SETUP TIME_PERIOD
    ---------- ---- ----- ------ --------------
    ABC-123    0081 X516      .0 12 mos. back
    ABC-123    0130 Z211      .5 12 mos. back
    ABC-123    0170 X928      .0 12 mos. back
    ABC-123    0324 Y000      .1 12 mos. back
    ABC-123    0120 H214      .3 24 mos. back
    ABC-123    0122 T203     2.5 24 mos. back
    ABC-123    0130 Z211      .5 24 mos. back
    ABC-123    0170 X928      .0 24 mos. back
    ABC-123    0324 Y000      .1 24 mos. back
    ABC-123    0324 Y000      .1 37 mos. back +
    

    The output is correct; the problem is, can we get the same results without 2 copies of the expression BOX wctr and 3 copies of the expression BOX time_period?
    What is a good description of the problem?

    To start, you can use aliases for columns in the ORDER BY clause. Unfortunately, it's the only place where you can use column aliases in the same query, where they are defined . You can calculate them in a query-sib and then use them in queries Super.
    In other words, wouldn't be nice if we had a table just like op_detail, but with an extra column called wctr? Make a view: either a regular view (especially if wctr, calculated in the same way, to be used for several different queries) or view online, as shown below.
    Wouldn't be great if there was a table that was like a, except that he had calculated alreay time_period? Make a view: either a regular view, or a view online, as shown below.

    SELECT     o.part_nbr
    ,     s.major_seq_nbr          AS op_nbr
    ,     s.wctr
    ,     MIN(s.plan_su_rsrc)          AS min_plan_setup
         -- lots of other agtgregates go here in real query
    ,     a2.time_period
    FROM     ord_master      o
    ,     (          -- Begin in-line view s, with data from op_detail
                 SELECT  op_detail.*      -- or list all columns needed in main query
              ,     CASE          -- replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                       WHEN     wctr_id        IN ('H211','H212')
                       THEN     'Z211'
                       ELSE     wctr_id
                   END                    AS wctr
              FROM     op_detail
         ) s          -- End in-line view s, with data from op_detail
    ,     (           -- Begin in-line view a2, to compute time_period
              SELECT  a.*
              ,     CASE
                       WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                           THEN     '12 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                           THEN     '24 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                           THEN     '36 mos. back'
                           ELSE '37 mos. back +'
                   END                         AS time_period
              FROM     a          -- in real query, a is an in-line view
         ) a2          -- End in-line view a2, to compute time_period
    WHERE     o.ord_nbr     = s.ord_nbr
    AND     o.sub_ord_nbr     = s.sub_ord_nbr
    AND     o.ord_nbr     = a2.ord_nbr
    AND     o.sub_ord_nbr     = a2.sub_ord_nbr
    AND     o.ord_type     = 'AA'
    AND     o.ord_stat     IN ('CL','OP')
    AND     s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          s.wctr
    ,          a2.time_period
    ORDER BY     o.part_nbr
    ,          a2.time_period
    ,          s.major_seq_nbr
    ;
    

    In your example, wctr is identical to wctr_id, except for two values. If it was more complicated (for example, if there is not only 2 values that must be mapped on 'Z211', but also 3 to did not amount to "Z987", and 1 which should be treated as "A012" and 5 who should appear as "A666" and...), then you pourriez encode this in an expression BOX humongeous (one nested expression BOX if it involves more than 128 branches) , but it actually belongs to a table, where you have the gross wctr_id (such as "H211") in a column and its equivalent correspondent (for example "Z211") in another. I know that you said that you cannot create new tables; I'm just pointing out that then you can tell people that won't let you create tables, it's a bad idea, likely to lead to errors and some time in the future.

  • Best way to set the default values for the form elements

    Hello

    I have a form with a lot of defaults that is mentioned below...
      Field                      value  
      created by             :APPL_USER
      creation_date         SYSDATE
      last_updated_by     :APPL_USER
      last_update_date    SYSDATE
      item1                     value1
      item2                     value2
    I am currently using calculation-> after presents... then when we create/update a record... these computaion takes place and the default value for the inserted values get... THIS WORKS PERFECTLY WELL.

    I want to know... If this approach is fine OR we can have a better approach to achieve...?

    Thank you
    Deepak

    Hello

    I think it's good if it fits your need.

    But why you have these fields in the form?
    created by: APPL_USER
    CREATION_DATE SYSDATE
    last_updated_by: APPL_USER
    last_update_date SYSDATE

    The user can enter the ones?
    I thought that those who are to audit and I would fill those drop with trigger in the database.
    So that you get the same "correct" values if you need to manipulate the data with example of sql client

    BR, Jari

  • The best way to find the name of the installed application module?

    If you don't know the name of an application module, how can you find it?

    For example, if I have the name of jad file from another application, can I assume that the name of the application module is basename of the jad?  As in, a name of jad MyApp.jad would result in a module name to 'MyApp '?

    That was my assumption in a first time, and it of that he seems to be the case, most of the time, but not all.  In particular, if the jad's name:

    MyApp - 1.0.0.jad

    I found that the name of the actual module on a "BOLD" v4.6.167 running (and the 4.6.0 JDE the bold Simulator) is

    MyApp$ 2 d 1

    However, * on an another "BOLD" * (this a v4.6.0.162 running), the exact same application indicates a module name of

    $ 2 d $1 2e0 MyApp$ 2e0

    That's why I wonder if there is way to get more definitive an application module.  I scoured the API documentation and the solution isn't jumping home.

    Thoughts?

    Thanks for any help.

    Ah.  I can also see if I need to 'escape' my module names.  If this isn't the case, then I can watch an exact match in the list of module names.  If I have, it seems that I still need to look for something, "close enough" and hope for the best.

  • How to find the maximum value of the alphanumeric column

    Hello

    I have following data varchar column.

    USR_UDF_ALPHANUMERIC
    --------------------------------
    234123
    CS/123762
    987643
    CS/990087
    999999
    CS/761287

    I'm looking to separate the 2 SQL queries which should get the output as CS/990087 for the first query and * 999999 * for the second query.

    database is 10g.

    As always: it is documented.

    See:
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions043.htm#i1064409

    And make a few quick searches yourself:
    http://www.Oracle.com/pls/db102/homepage
    or
    http://www.Oracle.com/pls/db112/homepage

  • How can I find the 'hidden' files that take more than 300 GB of space?

    "Get info" shows that I have close to 500 concerts in my user folder, but when I add each folder inside, it is only about 100 GB.  Where could hide these other files?  My garbage can is completely empty and I ran check disk on this drive and it shows no problem.

    Thanks for any help!

    KT

    Try this application.

    OmniDiskSweeper full - disk space 10.8 +.

  • What is the best way to get the minimum or maximum of a table of numbers value?

    Let's say I have a table of numbers: [2,3,3,4,2,2,5,6,7,2]

    What is the best way to find the minimum or maximum value in the table?

    Now, just get the maximum, I'm a loop in the table and reset a variable to the value if it is greater than the existing value:

    What I ended up doing was sorting table (descending to MAX) upward for MIN and then grabbing the first element of the array. Works like a charm in very few lines of code.

    Thank you.

  • Find the Maximum using the registry to offset

    Hello

    I'm trying to find the maximum value of the input signal and display in the front panel. I managed to achieved this for values that are positive. but when my signal is completely negative it does not update my max.

    I enclose my VI.

    Thanks for your help.

    Dylan

    Here is a quick sketch...

  • How to find the maximum and minimum of a waveform between cursors

    Hello!

    Does anyone know an easy way to find the maximum and minimum of a waveform between two sliders?

    Kind regards

    Andreas

    Hi Andreas,

    attached, you get an example of it in MeasurementStudio.

  • Apple Extreme, Time Capsule and Express on the same system, what is the best way to set it up so that all devices smoothly from one end of the House to another?

    Apple Extreme, Time Capsule and Express on the same system, what is the best way to set it up so that all devices smoothly from one end of the House to another?

    I'm going to assume that you plan to have wireless devices.

    Let's say that the Capsule is your "main" router  If this is the case, then it must be located in the House, so that the distance between the time Capsule is the same for the outside walls of the House.

    Then, on the 'left' side of the House, looking for an airport to midway between the Capsule and time of the outer wall of the House. Do the same thing the 'right' side of the House.

    In other words, each of the two airports that "extend" the wireless signal are located at equal distance from the Capsule of time... but they are in opposite ends of the House.

    If you intend to interconnect all the airports and Time Capsule using a permanent, Ethernet wired... which by far is the 'best' way to put in place a network in terms of performance and reliability... then you can locate one of the devices anywhere you want.

  • I'm moving from Vista to Windows 7. I get a question that tells me that I need a BIOS upgrade. I have an Inspiron 1720 laptop model. Is there a way to find the update is necessary?

    I'm moving from Vista to Windows 7. I get a question that tells me that I need a BIOS upgrade. I have an Inspiron 1720 laptop model. Is there a way to find the update is necessary?

    original title: bios update

    Hello

    you have a problem here as Dell does not have Windows 7 drivers available for your model of laptop etc, etc.

    Unfortunately, you need these Windows 7 drivers, etc. to upgrade to Windows 7

    read the information on your laptop on the link below

    http://support.Dell.com/support/downloads/DriversList.aspx?c=us&l=en&s=Gen&OS=WLH&OSL=en&SystemID=INS_PNT_PM_1720&CATID=-1&impid=-1

    For more information contact Dell about this

    Dell support:

    http://support.Dell.com/

    Dell support at the link above.

    http://en.community.Dell.com/support-forums/default.aspx

    Dell's Support Forums at the link above.

  • Find the maximum numeric value to a String

    Hi all

    I want to find the maximum number of the string using PLSQL. How can I do this simply.

    Example string: "D32X1U7".

    And I want to get maximum numeric value is of this string. (7)

    Thank you

    Something like this:

    SQL >

    SQL > with input_data (select ' D32X1U7' double Str).

    2 split_char AS (select substr (str, level 1) c

    input_data 3

    4. connect by level<=>

    5                     )

    6 select max (c)

    7 of split_char

    8 where the regexp_like (c, ' [[: digit :]]');]])

    MAX (C)

    ------

    7

    SQL >

Maybe you are looking for

  • Satellite A500 - error blue screen when I install XP

    I am trying to install XP on my laptop which has Vista. Boot from the disc I get the blue screen error because I do not have the sata drivers. I've read here,http://APS2.toshiba-tro.de/KB0/FAQ9401B20001R01.htm I need to download the sata drivers (whi

  • Protected dmg will not open, even with the RIGHT password

    I created a password protected DMG, and now this record does not, although I am sure that I use the password. After entering the PW, I get a message indicating that the password is incorrect: ' try again - please enter the password to access the [Fol

  • important update

    I'm trying to install the update for security update for Microsoft.NET Framework Version 1.1 Service Pack 1 (KB929729) and it will not be installed

  • Unable to see the photo in a Yahoo Group after downloading to my laptop

    Can someone tell me why I can't see the image after I download to a Yahoo Group?  I used to be able to.  I did all the usual things - copied an image of 'Photos' and then used the option "Browse" on the Yahoo Group. But it shows just a small red cros

  • No sound on my HP Sleekbook

    Hello world I have a HP Pavilion Sleekbook 15-b002ev with Windows 8.1. I experience the following problem. Sometimes I audio and sometimes I did, without a particular reason. I can watch a video without problem, but on the next video, the sound will