Need to take rownum highest value without using grouping functions

Hi
I want to display highest value in the rownum column and customer details without using grouping functions like max or count
this below query gives me all rownum values and customer details
SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER;
can any one help me.

The above query won't work as it's missing "from" cluase in the inner select statement.
And even if corrected it willl print rownum values thrice: value "1",max_rownum, max_rownum followed by customer details.
Below is the simple query to retrieve max row_num along with the corresponding customer details.
select * from (SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER order by rownum_1 desc) where rownum<=1 ;

Similar Messages

  • Max value without using max() function

    Hi
    Is there any way to get the max value from a table without using MAX() function
    Thanks

    well if you think about it i'm sure you'll find a solution
    what does max(field) means, it simply is the value of the field where no other value of the same field that is > than this value exists.
    consider the following :
    table TAB(
    fld NUMBER(5));
    translate the logic and you'll have
    select a.fld from TAB a where NOT EXISTS(select b.fld from TAB b where b.fld>a.fld) and rownum=1;
    of course there are better ways i'm sure, you'll just have to figure'em out.

  • Display the 3rd hieghest value without using rowid

    HI All,
    Can any one help me how to display the 3rd hieghest valuer without using a ROWID..
    Thanks
    Basava

    Frank, using ROWNUM = 1 instead of DISTINCT could be a bit faster:
    SQL> SET LINESIZE 132
    SQL> EXPLAIN PLAN FOR
      2  WITH got_r_num AS (
      3                     SELECT  DISTINCT sal,
      4                                      DENSE_RANK() OVER(ORDER BY sal DESC NULLS LAST) AS r_num
      5                       FROM  scott.emp
      6                    )
      7  SELECT  sal
      8    FROM  got_r_num
      9    WHERE r_num = 3
    10  /
    Explained.
    SQL> @?\RDBMS\ADMIN\UTLXPLS
    PLAN_TABLE_OUTPUT
    Plan hash value: 436395657
    | Id  | Operation                 | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |      |     9 |   234 |     5  (40)| 00:00:01 |
    |*  1 |  VIEW                     |      |     9 |   234 |     5  (40)| 00:00:01 |
    |   2 |   HASH UNIQUE             |      |     9 |    36 |     5  (40)| 00:00:01 |
    |*  3 |    WINDOW SORT PUSHED RANK|      |     9 |    36 |     5  (40)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL     | EMP  |    14 |    56 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("R_NUM"=3)
       3 - filter(DENSE_RANK() OVER ( ORDER BY INTERNAL_FUNCTION("SAL") DESC
                  NULLS LAST)<=3)
    18 rows selected.
    SQL> EXPLAIN PLAN FOR
      2  WITH got_r_num AS (
      3                     SELECT  sal,
      4                             DENSE_RANK() OVER(ORDER BY sal DESC NULLS LAST) AS r_num
      5                       FROM  scott.emp
      6                    )
      7  SELECT  sal
      8    FROM  got_r_num
      9    WHERE r_num = 3
    10      AND ROWNUM = 1
    11  /
    Explained.
    SQL> @?\RDBMS\ADMIN\UTLXPLS
    PLAN_TABLE_OUTPUT
    Plan hash value: 21859616
    | Id  | Operation                 | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |      |     1 |    26 |     4  (25)| 00:00:01 |
    |*  1 |  COUNT STOPKEY            |      |       |       |            |          |
    |*  2 |   VIEW                    |      |    14 |   364 |     4  (25)| 00:00:01 |
    |*  3 |    WINDOW SORT PUSHED RANK|      |    14 |    56 |     4  (25)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL     | EMP  |    14 |    56 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
       2 - filter("R_NUM"=3)
       3 - filter(DENSE_RANK() OVER ( ORDER BY INTERNAL_FUNCTION("SAL") DESC
                  NULLS LAST)<=3)
    19 rows selected.
    SQL> SY.

  • I want single update query without use the function.

    I want to update sells_table selling_code field with max date product_code from product table.
    In product table there is multiple product_code date wise.
    I have been done it with below quey with the use of function but can we do it in only one update query
    without use the function.
    UPDATE sells_table
    SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
    WHERE NVL(update_product_flag,0) = 0 ;
    CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
    IS
    max_date_product VARCHAR2 (100);
    BEGIN
    BEGIN
    SELECT NVL (TRIM (product_code), 0)
    INTO max_date_product
    FROM (SELECT product_code, xref_end_dt
    FROM product
    WHERE TO_NUMBER (p_product) = pr.item_id
    ORDER BY xref_end_dt DESC)
    WHERE ROWNUM = 1; -- It will return only one row - max date product code
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN 0;
    END;
    RETURN max_date_product;
    END maxdateproduct;
    Thanks in Advance.

    Hi,
    Something like this.
    update setlls_table st
            set selling_code =(select nvl(trim(product_code)) from 
                                  (select product_code
                                          , rank() over (partition by item_id order by xref_end_dt DESC) rn
                                       from product
                                   ) pr
                                   where rn =1
                                         and pr.item_id = st.ctd_vpk_product_code
                               ) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
    Regards
    Anurag Tibrewal.

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • Alternate without using regexp_replace function

    SELECT
      REGEXP_REPLACE(phone_number,
                     '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})',
                     '(\1) \2-\3') "REGEXP_REPLACE"
                     FROM employees;
    is there any alternate without using regexp_replace function.........

    Another way
    (eliminating instr function.. as your problem focusses on a fixed length)
    WITH t AS (SELECT '112.345.6789' str FROM DUAL),
         tt AS (SELECT REPLACE (str, '.') str FROM t)
    SELECT    '('
           || SUBSTR (str, 1, 3)
           || ') '
           || SUBSTR (str, 4, 3)
           || '-'
           || SUBSTR (str, 7)
      FROM tt;
    Cheers,
    Manik.

  • Error while using group function

    Oracle forms6i
    Hai
    While i am compile my coding it compile successfully, but when i tried to executes i shows error in group function
    my coding is
    if (cnt<>0 ) then
    select BARCODE,INTIME,OUTTIME into today_bar,today_in,today_out from dail_att where BARCODE= :Barcode
    and ATTEND_DATE = :bardate;
    update dail_att set outtime = max(:bartime) where barcode= :barcode
    and ATTEND_DATE = :bardate;
    else
    if (cnt2<>0 ) then
    select INTIME,OUTTIME into yest_in,yest_out from dail_att where BARCODE= :Barcode
    and ATTEND_DATE = :bardate-1;
    if(yest_in is not null and yest_out is null) then
    update dail_att set outtime =max(:bartime) where barcode= :barcode
    and ATTEND_DATE = :bardate-1;
    else
    insert into dail_att(barcode,intime,attend_date)
    values(:barcode,min(:bartime),:bardate);
    end if;
    else
    if :bartime between 0100 and 0630 then
    insert into dail_att(barcode,intime,attend_date)
    values(:barcode,min(:bartime),:bardate-1);
    update dail_att set outtime = max(:bartime) where barcode= :barcode
    and ATTEND_DATE = :bardate-1;
    else
    insert into dail_att(barcode,intime,attend_date)
    values(:barcode,:min(bartime),:bardate);
    end if;     
    end if;
    end if;
    while i am trying to this groupfunction it throws error while i use having tell me how to use group function and where
    to use
    Regadrs
    Srikkanth.M

    Hai sir
    I had a table that contain fields
    EMPCODE NUMBER
    EMPNAME VARCHAR2(25)
    BARCODE VARCHAR2(25)
    INTIME VARCHAR2(25)
    OUTTIME VARCHAR2(25)
    INTRTIMEIN VARCHAR2(25)
    INTROUTTIME VARCHAR2(25)
    PERTIMEIN VARCHAR2(25);
    PERTIMEOUT VARCHAR2(25);
    ATTEND_DATE DATE ;
    Consider that a table with 6 fields ie timein,intrtimein,pertimein,pertimeout,intrtimeout,timeout
    I have generating a attendance table and a table contain 6 various times for an employees and we need to arrange it in order
    0815,0816,1230,1250,1645,1646
    If 0815 is the starting time then timein ie mintime
    0816 stored to be in intrtime
    then1250 then it stored in pertimein
    then 1230 then it stored in pertimeout
    then 1645 stored in intrtimeout
    then 1646 stored in timeout
    I tried with max and min function but its not working properly pls tell me some solutions
    Thanks & Regards
    Srikkanth.M

  • How to use group function in insert or update

    Hai All
    How can we use group function in insert or update statement
    I am generating an attendance so i have different set of timing for example
    0800,1200,1230, 1700 and i need to insert into these data into table with min value to intime and max value to
    outtime and othere to inertval time in or out
    Pls tell me with some example
    For example
    For INSERT
    insert into T2 (barcode,empcode,intime,attend_date)
                   values(r2.cardn,r2.enpno,MIN(r2.ptime),r2.pdate);
    For UPDATE
    update dail_att set outtime= MAX(r2.ptime) where empcode=r2.enpno and barcode=r2.cardn and
    attend_date=r2.pdate;
    Here instead of where i need to use having so pls tell how to use
    Thanks & Regards
    Srikkanth.M

    Hai Man
    R2 is not a table name its a record
    Let me explain clearly
    I have to generate daily attendance for lot of employees So i have two table t1 and t2
    T1 consist of three column empno,date,time
    T2 consist of empno,name,date,intime,outtime,intrin,introut
    So now i need to give the T1 Min value Of time to T2 Intime and T1 Max value of Time to T2 Outtime fields so there so many records while i am using
    max(time) it gives the max value of all so i seperated by group function so now i have an error in subquery ie it is an single row subquery so i need to use multiple row subquery how i can use multiple row subquery in update statement
    Thanks In Advance
    Srikkanth.M

  • How to set item values without using fields in branch's ACTION block?

    Okay, I will try to say this in a easy way so it is not weird.
    I have created a button, SAVE, that has a Branch of branch type: Branch To Function Returning A Page. This is my code for the branch:
    if :P2008_NAP_SUPPORTING_MATERIALS = 'Yes' then
    return '2092';
    else
    return '2040';
    end if;
    The code for this type of branch is stored in the ACTION block of the Branch page. The ACTION block for a Branch of branch type: Branch To Function Returning A Page is different than the ACTION block for a Branch of branch type: Branch To Page Or URL.
    I need to set some item values with some specific values, which I can do with a branch type: Branch To Page Or URL. This is not possible with the branch type: Branch To Function Returning A Page. The ACTION block is totally different.
    How can I set some values on say Page 2040 from Page 2008 without using fields in the branch's ACTION block?
    Thank you in advance,
    Maggie

    Andy and Scott,
    I love seeing different perspectives in solving problems, it opens my eyes to new ways of looking at/using the tools (reserved words and 'Function returning a Page', etc.).
    One of my pet peeves has been that on branches I was limited to only 10 variables to be passed (I know, who would want more - but there was an instance where I had to pass more), and an even more frustrating time when using report Column Linking, which limits me to 3 variables.
    At least with the Branch linking I can use your suggestion Andy and add the variable setting statements into the function. I am assuming of course (and I should be able to) that I will be able to set more that 10 variables in a IF condition prior to the RETURN statement. This method will be much more understandable, for me, when looking through the branch at a later time to see what is happening, than an URL link where all the variable are strung out 'in a line' so to speak.
    I will still need to use URL Target branching on Links contained within a Column Attribute when I need to pass more than 3 variables, of which I have several places where I do this.
    Thomas

  • Function that returns N values, without using a string

    Hi, how can i make a function that returns several valures (that hasn't a exact number of returned values, it could return 3 values, or 7) without using a string?
    When i need to return several values from a function, i put the values inside a varchar like thus 'XXX,YYY,ZZZ' and so on. Don't know if this has a poor performance.
    If you can supply simple examples for what im asking, i would be nice.
    (without using a string)

    Can i create the type objects inside a package? If i
    can, they will be local to the package, right?Yes, you're right.
    Pipeline returns a row or several?You can use pipelined function in the same way you use table:
    SELECT * FROM TABLE(pipelined_funct(agr1, agr2));
    It returns results as separate rows.

  • Is there any way to wait for a value without using JDialog or JOptionPane?

    I am implementing a dictionary program by detecting word in a JTextPane and asking a user to choose one of available meanings from JOptionPane or JDialog. The program runs under a while-loop until all dictionary words are detected or a user clicks cancel.
    However, I don't want to use JDialog or JOptionPane because it is sometimes annoying to have a popup window on every detected dictionary word.
    So, I use JList with Buttons on the same Frame as the JTextPane. However, now, the program does not stop when it detects a dictionary word. It just uses a default value of the JList for translating word to meaning.
    Is there any way I can simulate the JDialog or JOptionPane without using it?
    I mean I'd like to stopp the program temporary, wait for an answer from other components, and then continue to detect the next dictionary word.
    Thank you.

    I'm probably reading this all wrong, but instead of the while loop,
    the method just looked for a dictionary word from a particular caretPosition,
    so, to start, it would be findWord(0)
    when found, add whatever to wherever, note the caretPostion at the end of the 'found' word, and method returns.
    when the user selects whatever button, the button's actionListener also calls the method again, using the noted caretPosition
    findWord(42);
    so, it starts searching from 42 (instead of the start)
    basically it is event driven
    findWord sets the button/s
    click a button starts findWord

  • Sort Rowset field values without using rowset.sort or sortscroll

    Hi dudes,
    any one tell me the different ways to sort a rowset values ie, single field or more than one field without using Rowset.sort or Sortscroll() method. i tried some ways but not get the optimum solution.

    My first question to you would be why you want alternatives for Rowset.sort or Sortscroll.
    Your question doesn't describe your true issue or motive to search for alternatives for delivered PeopleTools Apis & Buildin Functions.

  • Print a DayName without using Date functions

    Hi,
    I have an assignment like without using any date functions i should print a calendar.
    Below is the code without using any datefunctions like dateadd, datediff, datename a calendar has been generated for month and year entered. I want a week name for the dates like sunday ... monday etc. 
    I can take any date from calendar as reference  and calculate based on that date.
    ex: today is 2/20/2014 thursday . Next 7days again will be thursday, same way before 7days will be thursday.
    I need to loop in below procedure and get weekname. 
    Plz help in the code,
    I am using SQL server 2008
    IF OBJECT_ID ('dbo.Calendar1') IS NOT NULL
         DROP PROCEDURE dbo.Calendar1
    GO
    CREATE  PROCEDURE [dbo].Calendar1 --4,1991
       @month int,
       @Year  int
     AS  
     BEGIN
     declare 
     @startdateofMonthYear date,
     @EnddateofMonthYear Date
    Set @startdateofMonthYear=(Select cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'01')
    Set @EnddateofMonthYear = (SELECT case when @month IN (1,3,5,7,8,10,12) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'31'
    when @month IN(4,6,9,11) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'30'
    else  cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+(CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN '29' else '28' End) 
    End) 
    ;WITH CTE_DatesTable
    AS
    Select 1 daysint, Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(1 as varchar(2)) as DATE) Calendardates
    UNION ALL
    SELECT   daysint+1,Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(daysint+1 as varchar(2)) as DATE) Calendardates
    FROM CTE_DatesTable
    WHERE  daysint<= 
    (SELECT case when @month IN (1,3,5,7,8,10,12) then 31
    when @month IN(4,6,9,11) then 30
    else  (CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN 29 else 28 End) 
    End)-1
    Select 
    [DWDateKey]=Calendardates,
    [DayDate]=daysint,
    [MonthNumber]=@Month,
    [MonthName]=Case when @month = 1 then 'January'
     when @month  = 2 then 'February'
     when @month  = 3 then 'March'
     when @month  = 4 then 'April'
     when @month  = 5 then 'May'
     when @month  = 6 then 'June'
     when @month  = 7 then 'July'
     when @month  = 8 then 'August'
     when @month  = 9 then 'September'
     when @month  = 10 then 'October'
     when @month  = 11 then 'November'
     when @month  = 12 then 'December' 
    End,
    [Year]=@Year
    From CTE_DatesTable
    END
    bhavana

    In the above code, where do i pass the year and month?
    (Select 2000 YearID
    Union All
    Select YearID +1 From cte where YearID <2100
     In above condition from 2000 year its displaying.
    If i want in 90's year , Day name will not be correct.
    Deepa

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Count the no.of rows without using count function

    Hi,
    How to count the no.of rows without using the count function?
    Thanks,

    they won't be 100% accurate. You're correct, Bluefrog, but the same goes for doing a count(*) (depending on the size of the table, ofcourse):
    the table being queried might be under DML (deletes/inserts), and the next count(*) might give different results.
    Both approaches will never be 100% accurate.
    But simply selecting num_rows will be much much faster than doing a count(*).
    Counting the number of rows always reminds me of this ongoing discussion, by the way:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:127412348064#14136093079164 ;)
    Usually knowing the number of records by approximatly is sufficient, imo. 1000000 or 1000007 records: I don't care, don't need to know that.
    I've never needed to know the exact number of records in a table in my code, or been given a requirement that forced me to.

Maybe you are looking for

  • Converted Video on Apple TV

    Can you put video from DVDs that have converted for Video iPod on to Apple TV? Can you only have Movies, TV Shows, Music Videos,etc. that you purchase on iTunes (or not)? Thanks, TVK

  • BOM ALE issue

    Hello all,    I am trying to ALE BOM changes from client 300 to 100. SO I changed the qauntity of a component and saved without using ECM . I did the ALE, but in target system it did not update the item quantity. Instead it added a new line item with

  • Retrieve file/directory listing from a URL

    I am building an applet to view images located on a given URL (not the same as the codebase URL...). The problem is how to see which directories and files that are located on the given URL? File.list() works fine as long as I'm the pictures are locat

  • Stacked VLAN (802.1Q-in-Q)

    Hi, I would like to know if the Catalyst 6500 (Sup720-3b) supports the fonctionnality Stacked VLANs (802.1Q-in-Q) And if Yes, in witch IOS version. Thanks for your help

  • Ibook no longer recogonizes shuffle

    i've been using my shuffle since march of last year without problems, and last week my ibook would no longer recognize my shuffle. is this the end? before the battery drained completely, the lights on the ipod were still working and i could still lis