Group by- Max values+equal values

Hi Experts,
I am looking for a query where i can group the data accordingly and exclude the rows which i don't need.please help to arrive this.
i have the data like this in my table
Cust_id type count
10 abc 19
10 abcde 19
10 abcde 8
20 e 8
20 u 4
30 f 30
I need the out put like this
Cust_id type count
10 abc 19
10 abcde 19
20 e 8
30 f 30
Thanks
Bharat

This?
SQL>  with abc as
  2   (
  3   select 10 Cust_id,'abc' type,19 cnt from dual union all
  4   select 10, 'abcde', 19 cnt from dual union all
  5   select 10, 'abcde', 8 cnt from dual union all
  6   select 20, 'e', 8 cnt from dual union all
  7   select 20, 'u', 4 cnt from dual union all
  8   select 30, 'f', 30 cnt from dual
  9   )
10   select cust_id,type,cnt
11   from
12   (
13     select cust_id,type,cnt,
14            count(*) over(PARTITION BY cust_id,cnt) cnt1
15     from
16     (
17       select cust_id,type,cnt,
18              rank() over(PARTITION BY cust_id ORDER by cnt DESC) rn
19       from abc
20     )
21     where rn = 1
22   )
23   where cnt1 = 1;
   CUST_ID TYPE         CNT
        20 e              8
        30 f             30

Similar Messages

  • Subtotal less than or equal to a max value

    Hi,
    I have the following values in a table:
    drop table t;
    create table t (key number, ind varchar2(1), num number);
    insert into t (key,ind,num) values (1,'Y',2);
    insert into t (key,ind,num) values (2,'Y',10);
    insert into t (key,ind,num) values (3,'Y',12);
    insert into t (key,ind,num) values (4,'Y',9);
    insert into t (key,ind,num) values (5,'Y',1);
    insert into t (key,ind,num) values (6,'Y',1);
    insert into t (key,ind,num) values (7,'Y',8);
    insert into t (key,ind,num) values (8,'Y',1);
    insert into t (key,ind,num) values (9,'N',11);
    insert into t (key,ind,num) values (10,'N',6);
    commit;The values are:
    test@ORA92> select * from t order by key;
           KEY I        NUM
             1 Y          2
             2 Y         10
             3 Y         12
             4 Y          9
             5 Y          1
             6 Y          1
             7 Y          8
             8 Y          1
             9 N         11
            10 N          6
    10 rows selected.
    test@ORA92>For all rows with ind = "Y", I want to add "num" as long as the subtotal is less than or equal to a max value (15). For all rows with ind = "N", I want the sum of "num".
    It should be as follows:
           KEY I        NUM
             1 Y          2    <- consider this, as subtotal is now 2 which is < 15
             2 Y         10   <- consider this, as subtotal is now 12 which is < 15
             3 Y         12   <- ignore this, as subtotal would be 24 which is > 15; keep running total as 12.
             4 Y          9   <- ignore this, as running total would be (12+9=) 21, which is > 15; keep running total as 12
             5 Y          1   <- consider this, as running total is now (12+1=) 13, which is <= 15
             6 Y          1   <- consider this, as running total is now (13+1=) 14 which is <= 15
             7 Y          8   <- ignore this, as running total would be (14+8=) 22, which is > 15; keep running total as 14
             8 Y          1   <- consider this, as running total is now (14+1=) 15, which is <= 15
             9 N         11 <- add this to subtotal for ind = "N"; subtotal = 11
            10 N          6 <- add this to subtotal for ind = "N"; subtotal = (11+6=) 17
    Return "ac" (subtotal for ind = "Y") = 15 - the one we got at key = 8
    Return "dc" (subtotal for ind = "N") = 17 - the one we got at key = 10I have a pl/sql block that does the same:
    test@ORA92>
    test@ORA92> --
    test@ORA92> -- To derive "ac" value:
    test@ORA92> --   Loop through t, and for ind = "Y", keep on adding "num" as long as
    test@ORA92> --   the subtotal is less than "maxnum". Disregard values of "num"
    test@ORA92> --   that would make the subtotal greater than "maxnum".
    test@ORA92> -- To derive "dc" value:
    test@ORA92> --   Sum of "num" values for ind = "N"
    test@ORA92>
    test@ORA92>
    test@ORA92> declare
      2    maxnum   number := 15;
      3    ac       number := 0;
      4    dc       number := 0;
      5    prev     number := 0;
      6  begin
      7    FOR i IN (SELECT ind, num
      8                FROM t
      9              ORDER BY key)
    10    LOOP
    11       IF (i.ind = 'Y') THEN
    12          ac := i.num + prev;
    13          IF (ac > maxnum) THEN
    14             ac := prev;
    15          ELSE
    16             prev := ac;
    17          END IF;
    18       ELSIF (i.ind = 'N') THEN
    19          dc := i.num + dc;
    20       END IF;
    21    END LOOP;
    22    dbms_output.put_line('maxnum  = '||maxnum);
    23    dbms_output.put_line('ac      = '||ac);
    24    dbms_output.put_line('dc      = '||dc);
    25    dbms_output.put_line('prev    = '||prev);
    26  end;
    27  /
    maxnum  = 15
    ac      = 15
    dc      = 17
    prev    = 15
    PL/SQL procedure successfully completed.
    test@ORA92>
    test@ORA92>Is there a way to do this processing in SQL instead ? The database version is 9i R2 (9.2.0.8.0).
    Thanks and appreciate any help and/or pointers.
    pratz...

    Rob, as it was mentioned here it can be done by Hierarichal Queries, disregarding a lot of drawbacks of such a way.
    SQL> with temp as (select t1.*,
      2                 (select case  when t1.ind = 'Y' and sum(num) > 15
      3                               then  null
      4                               else  sum(num)
      5                         end
      6                    from t t2
      7                  connect by level <= t1.lvl
      8                         and t2.key =
      9                             regexp_substr(t1.path, '[^/]+', 1, t1.lvl - level + 1)
    10                   start with t2.key = t1.key) summa
    11            from (select t.*,
    12                         level lvl,
    13                         sys_connect_by_path(key, '/') path,
    14                         sys_connect_by_path(rn, '/') path_rn
    15                    from (select t.*,
    16                                 lpad(row_number() over(partition by ind order by key),2,'0') rn
    17                            from t) t
    18                  connect by prior key < key
    19                         and prior ind = ind
    20                   start with (key, ind) in
    21                              (select min(key), ind from t group by ind)) t1)
    22  --
    23        select ind, avg(summa) keep(dense_rank first order by path_rn) max_summ
    24          from (select temp.*,
    25                       decode(instr(lead(path_rn) over(partition by ind order by path_rn), path_rn),1, 0, 1) flag
    26                  from temp
    27                 where summa is not null)
    28         where flag = 1
    29         group by ind
    30  /
    IND   MAX_SUMM
    N           17
    Y           15
    SQL>

  • Min and MAx Value in a SELECT Statement

    Hi,
    I have a scenario where I am Selecting the values BETWEEN MIN and MAX values:
    SELECT * FROM ABC WHERE CODE BETWEEN MIN(CODE) AND MAX(CODE)
    ITS GETTING Error as:ORA-00934: group function is not allowed here
    Any help will be needful for me.

    select substr(no,1,3)||to_char(substr(no,4,1)+1) "first missing number"
    from
    with t as
    (select 'ABC1' no from dual
    union select 'ABC2' from dual
    union select 'ABC3' from dual
    union select 'ABC5' from dual
    union select 'ABC6' from dual
    union select 'ABC8' from dual
    select no, lead(no,1,0) over (order by no) next_no from t
    where substr(next_no,4,1) - substr(no,4,1) > 1
    and rownum = 1;

  • Need to sum max values in a report with Hidden groupings

    I have looked all over and have not found my exact situation, so I am posting my first question.  I have a report that I have grouped on multiple levels.  So my report has a customer/header/detail/release grouping.  I have written a custom
    expression so that only a single value, which is the max value in the group, is shown in the detail, with all values showing in the release.  I have then set my visibility toggle to toggle on header, then detail, then release and I need to sum up those
    max values into a field on the report.  The custom expression that I have written works correctly when you are showing on the detail level.  It gives the correct value, which is the max value in each release.
    What I then need the report to do is to sum only that max value and roll that up into the header group, so that I get a total of the max values.  
    I have tried using the MAX function in my expression to get the correct max value, but I cannot get SSRS 2008 R2 to sum that, and I have tried writing a custom expression that will calculate the max (Non-zero values divided by number of non-zero records) and
    both ways work correctly until I try to rollup and sum to the next group level.
    I have also tried using a group variable and custom code to get the value and save it to a variable, but I have not had any luck in setting or getting that value correctly back to my report.
    At its most basic it feels like I should be able to set a Sum(Max(Fields!ValueColumn.Value) and let SSRS handle how that should be broken out, but after trying that repeatedly I have still had no luck.  I cannot adjust the SQL as I need the level of detail
    that the report shows, although I could add more fields as long as I don't add any groupings or totals that would reduce the granularity of that data being returned.
    Any new avenue to explore would be very helpful.
    Thank you in advance,
    Chad
     

    Ok, after continuing to search the internet I finally found the extra piece that I was missing that gave me the results I needed. The new expression looks like this:
    =runningvalue(Sum(Max(IIF(LEFT(Fields!JobNum.Value,1)="S" AND Fields!Week1STol.Value<>0, CDBL(Fields!Week1STol.Value), 0),"JobItem"),"JobItem"),SUM, "JobItem")
    In this I wrapped the original expression of Max in both a Sum and a runningvalue both at the JobItem level to get this rollup value. Now when I open the grouping I get the correct running value at each level.
    What this really gives to me is a running total at each of four groupings, even with a "max" value at the detail level. This also allows me to total a max value inline on the report, without needing a hidden row, or report footer.
    Thank you to everyone who looked at this, I hope it helps someone else. If this answer is not clear enough, please don't hesitate to add to the comments and I will try to clarify.
    Thank you, Chad

  • SSAS Tabular DAX- Need to get MAX value of the MIN (top)hierarchy level row

    EDIT:
    I got closer to resolving the issue using MAX. 
    However, If I remove the department hierarchy and just place on the MAX measure I get the single largest value out of all departments. 
    It would be ideal if the measure could still SUM the "top level" values across everything in the system if the hierarchy is not placed on the rows grouping.
    So it returns the largest value for a given department, but if the department hierarchy isn't present I need it to return a SUM of all the level 1 values for all departments...
    Basically return MAX value from the MIN L1ID's DeptLevel value, but I can't seem to construct that DAX query.  So if DepartmentID hierarchy is on display it gets MAX per row, but if that is removed it dips into MAX GoalValue for each L1ID grouping with
    the MIN DeptLevel.
    /EDIT
    I have a rather odd data table I'm bringing into a SSAS Tabular model.
    Instead of having all data at each child level and then it adding up to a grand total in the parent, it has a grand total predefined at each child level.
    I just need this tool to display the raw data if at all possible instead of trying to aggregate everything. Filter on active level, ignore child levels.
    Is there a way to do that?
    Example:
    SalesGoalsByDepartmentLevel:
    Level1 (top level) = 5,000
    Level2( lower level) = 0
    Level3(lower still) = 500
    Level 4(lowest) = 4,250
    So note that adding up all the child levels is still $250 shy of the top 5,000.
    IT is just an odd business rule, basically each level is expected to meet that goal or exceed it, the top level goal is 5,000 but management doesn't care where that last 250 comes from, they do are that each defined level is met.
    These levels are in a hierarchy so if I view the top level of the hierarchy it adds up to 4250+500+5000=9750 when I just want to see 5,000 at the top level and the details when they drill down.
    I added a filter to just filter to the top level, but then when I drill down of course those lower levels are blank.
    Is there a way to filter on the current displayed level without aggregating all child levels?
    Thanks!

    You might want to take a look at the Parent-Child Hierarchies pattern here:
    http://www.daxpatterns.com/parent-child-hierarchies/
    You might write DAX code to check what is the "current" level (see BrowseDepth measure in the sample file you can download) and depending on its level, se the filter to blank to all the levels below, so you don't aggregate "children".
    Just an idea, I'm not sure if it corresponds to your requirement and I don't have time to make more tests.
    I hope it will be helpful.
    Marco Russo (Blog,
    Twitter,
    LinkedIn) - sqlbi.com:
    Articles, Videos,
    Tools, Consultancy,
    Training
    Format with DAX Formatter and design with
    DAX Patterns. Learn
    Power Pivot and SSAS Tabular.

  • Query to print the max value of time of the latest record from table

    hi
    i wrote this query
    which should return max fx_time of the latest or current value of fx_date
    plz help
    this wuery is giving current date fx_date but with all values not the max value of fx_time.
    select FX_DATE, FX_TIME,FROM_CURRENCY, TO_CURRENCY, ASK_RATE, BID_RATE,
    time_stamp, source,
    DESCRIPTION, FX_TYPE, OVERRIDDEN_RATE, OVERRIDDEN_BY, OVERRIDDEN_DATE ,
    ASK_RATE_INVERSE, BID_RATE_INVERSE, PX_LAST, PX_MID, PX_OPEN, PX_HIGH,
    PX_LOW,NY_TIME_OF_LAST_PRICE_UPDATE,
    DATE_OF_LAST_UPDATE, PX_BID_AM, PX_ASK_AM, PX_BID_PM, PX_ASK_PM, PX_CLOSE_1D,
    CHG_NET_1D,
    CHG_PCT_1D, PRICING_SOURCE, PX_BID_1M, PX_ASK_1M, PX_BID_1YR, PX_ASK_1YR,
    PX_CLOSE_MTD,
    PX_CLOSE_YTD, FXOPT_COMMODITY_CCY, FXOPT_SPOT_FXRATE, SPOT_RT_USD_FLAG,
    PRIOR_CLOSE_BID,
    PRIOR_CLOSE_MID, PRIOR_CLOSE_ASK from CURRENCY_EXCHANGE_TXN
    WHERE
    source='BLOOMBERG'
    AND FX_DATE=
    (select max(fx_date) JIM from CURRENCY_EXCHANGE_TXN
    ,(select max(fx_time) TIM from CURRENCY_EXCHANGE_TXN GROUP BY FX_TIME )
    what change should i do

    Hi,
    Try this:
    select FX_DATE, FX_TIME,FROM_CURRENCY, TO_CURRENCY, ASK_RATE, BID_RATE,
    time_stamp, source,
    DESCRIPTION, FX_TYPE, OVERRIDDEN_RATE, OVERRIDDEN_BY, OVERRIDDEN_DATE ,
    ASK_RATE_INVERSE, BID_RATE_INVERSE, PX_LAST, PX_MID, PX_OPEN, PX_HIGH,
    PX_LOW,NY_TIME_OF_LAST_PRICE_UPDATE,
    DATE_OF_LAST_UPDATE, PX_BID_AM, PX_ASK_AM, PX_BID_PM, PX_ASK_PM, PX_CLOSE_1D,
    CHG_NET_1D,
    CHG_PCT_1D, PRICING_SOURCE, PX_BID_1M, PX_ASK_1M, PX_BID_1YR, PX_ASK_1YR,
    PX_CLOSE_MTD,
    PX_CLOSE_YTD, FXOPT_COMMODITY_CCY, FXOPT_SPOT_FXRATE, SPOT_RT_USD_FLAG,
    PRIOR_CLOSE_BID,
    PRIOR_CLOSE_MID, PRIOR_CLOSE_ASK from CURRENCY_EXCHANGE_TXN
    WHERE
    source='BLOOMBERG'
    AND FX_DATE=
    (select max(fx_date) JIM from CURRENCY_EXCHANGE_TXN
    FX_TIME )
    [PRE]
    Please always use [ PRE ]  and [ / PRE ] tags when ever posting any code.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Crystal Report Formula to select Record  of only MAX Value

    hi Everyone,
    i need a simple crystal report formula to select one department whose recived quantity Maximum.
    for example:
    itemcode    dscription      departmen   op       recived       issue        
      1                   a                ab               2              2              2         
      1                   a                bb              0             2              2          
      1                   a                bc               4             8              2         
      1                   a                cc              2              2              2
    i group by item  the item show just once but i want a formula to show one department who's recived quantity is maximum.i suppress the detail section.and just show the group footer/
    itemcode    dscription      departmen   op       recived       issue        
      1                   a                  bc                 8             14             8 

    Thanks
    Re: Crystal Report Formula to select Record  of only MAX Value
    Abhilash Kumar

  • Open cursor exceeds max value

    Hi,
    i am running 10.2.0.1.0 and the max value for open_cursor is set to 300.
    Earlier my developers were getting ORA-01000 errors. However when i checked again after two days i see the number is 1605 which is way higher than the max value. Why don't I see any errors now?
    Does anyone know??
    Thanks.
    Shawn

    SQL> SELECT COUNT(*) FROM v$open_cursor;
    COUNT(*)
    1522
    and i ran this to check each SID and the number of session which is giving me a better output and like you said the max value is based on per session.
    SELECT SUBSTR(a.SID,1,10) SID,
    SUBSTR(NVL(b.program,machine),1,30) program,
    COUNT(*)
    FROM v$open_cursor a, v$session b
    WHERE a.saddr=b.saddr
    GROUP BY SUBSTR(a.SID,1,10),
    SUBSTR(NVL(b.program,machine),1,30)
    ORDER BY 3 DESC
    Thanks for the help.

  • How to set upperbound key to a max value ?

    Hello,
    I use TreeMap.subMap() method as below:
    entrySet = iCumTotalsTree.subMap(iCumTotalsKey,iCumTotalsUpperKey).entrySet();
    The class of the key parameters of this subMap is as below:
    class:
    { int lineNumber
    int dep
    I want to get a sub map. So that the "dep" field of higher bound has always to be greater than or equal to "dep" field of lower bound.
    is it possible to return this sub map without identifying a value for the "dep" value of higher bound. I mean can I derive it from the "dep" value of lower bound ?
    thanks in advance...
    I need that dep field of second key should

    Hi,
    Thanks for the reply.
    I mean
    Lower bound should be:
    (<x1>,<y1>)
    Upper bound should be:
    (<x2>,<y2>)
    I can not pass a value to <y2>. But, I'm sure it's always greater than, or equal to <y1>. So, I need to derive <y2> from <y1>.
    I can use max value of integer for <y2>. But, is there a better way ? For example, does <y1+"\0"> work ?
    thanks in advance...

  • Get max value with other fields

    Hi All,
    I have a table as below
    Name Value
    A1     5
    A3 10
    A2 7
    A2 9
    A1 10
    What I would like to get is the max(Value) and with grouping of its name
    Name     Value
    A2 16
    Thanks
    Alex
    Edited by: user8606416 on 01-Jun-2011 10:17
    Edited by: user8606416 on 01-Jun-2011 10:26

    Depending on how you feel about ties one of:
    SELECT name, value
    FROM (SELECT name, SUM(value)
          FROM table
          GROUP BY name
          ORDER BY 2 DESC)
    WHERE rownum = 1
    SELECT name, SUM(value)
    FROM table
    GROUP BY name
    HAVING SUM(value) >= ALL (SELECT SUM(value)
                              FROM table
                              GROUP BY name)among many other methods. The first will pick a single arbitrary record in case of a tie, the seond will show all of the tied records.
    John

  • Daily max(value) query for time period

    I am looking to get the maximum value for every 24 hour period for a month. So for example my date range can be defined by...
    select to_date('&date','mm yyyy')-1 + level as DateRange
    from dual
    connect by level <= '&days'
    ...where I can provide the first date of the month and number of days in the month or a lesser value if less time is required. So, the results of the above query plus 24 for the range. I thought a some googling would provide me what I needed, but my search came up empty.
    I was hoping to do something like this...
    select utctime, max(value) from table where utctime between....
    Any guidance would be much appreciated!
    Thanks!

    Zewbie wrote:
    Sorry about that...Oracle 10.2.0.5
    create table x (utctime date,
    pointnumber int,
    value float)
    insert into x values (to_date('02022012 232221','mmddyyyy hh24miss'), 10, 3.245);
    insert into x values (to_date('02022012 202202','mmddyyyy hh24miss'), 13, 14.5);
    insert into x values (to_date('02024012 103421','mmddyyyy hh24miss'), 10, 23.245);
    insert into x values (to_date('02024012 042528','mmddyyyy hh24miss'), 10, 33.245);
    insert into x values (to_date('02028012 022321','mmddyyyy hh24miss'), 14, 32.245);
    insert into x values (to_date('02028012 205221','mmddyyyy hh24miss'), 10, 2.245);
    insert into x values (to_date('02029012 211421','mmddyyyy hh24miss'), 14, 1.4345);
    insert into x values (to_date('02029012 082221','mmddyyyy hh24miss'), 10, 3.245);Do you have dates 7000 years in the future, or ido you have typos?
    So a query of the above would provide max daily value based on a pointnumber such as 10 for a given period.What are the results you want from the given data?
    What role does pointnumber play in this problem?
    If you want something like this:
    A_DATE      POINTNUMBER  MAX_VALUE
    02-Feb-2012          10      3.245
    02-Feb-2012          13       14.5
    02-Feb-2012          14
    03-Feb-2012          10
    03-Feb-2012          13
    03-Feb-2012          14for the 2 days starting with February 2, 2012, then you can do this:
    WITH   days_wanted     AS
         SELECT  DATE '2012-02-02'     -- starting date
                  + LEVEL - 1     AS a_date
         FROM     dual
         CONNECT BY     LEVEL  <= 2     -- number of days wanted
    SELECT    d.a_date
    ,       x.pointnumber
    ,       MAX (x.value)   AS max_value
    FROM       days_wanted  d
    LEFT OUTER JOIN        x  PARTITION BY (x.pointnumber)
                                   ON  TRUNC (x.utctime)  = d.a_date
    -- WHERE  x.pointnumber       = 10         -- If wanted
    GROUP BY  d.a_date, x.pointnumber
    ORDER BY  d.a_date, x.pointnumber
    ;

  • 50 max values

    Hi all,
    I am new to LabView and have a question most of you may find simple. I am trying to collect torque signals from an isokinetic dynamometer and need to collect the 50 highest (max) values in the order in which they occur. I know how to find the maximum and minimum values, but need the highest 50. Thank you so much.

    Depending on the size of your array another method you could use would be to make a copy of the array, sort it from largest to smallest and grab the 50th element of the array. Next, initialize an array of size 50. Now run your original data into a FOR and use autoindexing to iterate over your array. If the value is equal to or larger than the minimum value you determined replace the nth value of your max array. You will need to keep track of the index that you will need to replace using a shift register. You can stop the loop once you have processed your entire array or you find the first 50 maximum values. This seems a bit complicated but you did say that you wanted your max array to maintain the order of the values from your original data. I am not sure that Ravens approach would do that for you.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Find Index for max value of array

    I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
    array:
    <cfset arrAverages[1]="#qryFairness.fairness#"/>
    <cfset arrAverages[2]="#qryHonesty.honesty#"/>
    <cfset arrAverages[3]="#qryCompassion.compassion#"/>
    <cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
    <cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
    These values are gathered from querying values stored in a table.
    I can get the max value in the array easily by:
    <cfdump var="#arrayMax(arrAverages)#">
    What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
    Thanks,
    Richard

    rking1966 wrote:
    I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
    array:
    <cfset arrAverages[1]="#qryFairness.fairness#"/>
    <cfset arrAverages[2]="#qryHonesty.honesty#"/>
    <cfset arrAverages[3]="#qryCompassion.compassion#"/>
    <cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
    <cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
    These values are gathered from querying values stored in a table.
    I can get the max value in the array easily by:
    <cfdump var="#arrayMax(arrAverages)#">
    What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
    You can find it in one line of code! Here is an example:
    <cfset testArr[1]=-183>
    <cfset testArr[2]=79>
    <cfset testArr[3]=6>
    Max.:  <cfoutput>#arraymax(testArr)#</cfoutput><br>
    Index of max.: <cfoutput>#arrayfindNocase(testArr, arraymax(testArr))#</cfoutput>

  • How to get max value of a column in VO?

    Hi ,
    i need to find the max value of a column named insured value in VO.
    Please help!!

    Hi,
    If this value is cuming from the Query then u can easily go for MAX function. If its a user enterable value then u need to iterate through all the rows for that column to find the max of them.
    Let me know.
    Regards,
    Gyan

Maybe you are looking for