Another MAX()  function question...

Help was provided earlier for a question I had regarding use of the MAX function... This also pertains to that. I have two tables, employee and movie. I want to find the name of the employee who has entered the most amount of movies into our database. The query I have come up with so far (it's a little messy) is:
SQL> select firstname, max(m) from (select firstname, count(enteredby) m from em
ployee, movie where enteredby = id group by firstname) group by firstname;
FIRSTNAME MAX(M)
Peter 6
Swanson 5
Kevin 7
Beverly 3
So I have this table returned, now in this case I want to be able to select from this subquery the first name "Kevin", since he has entered in the most movies. In my head this seems so easy, "Grab the firstname of the person whose max(m) is the largest", but I am just having trouble getting this thought translated into a proper query!

You can always do
SELECT firstname
  FROM (SELECT firstname, RANK() OVER (ORDER BY max_m) rnk
          FROM (<<your query>>))
WHERE rnk = 1Note that you'll need to alias the MAX(m) result first. You could also do
SELECT firstname
  FROM (
SELECT firstname, RANK() OVER( ORDER BY cnt) rnk
  FROM (SELECT firstname, COUNT(enteredby) cnt
          FROM employee e, movie m
        WHERE enteredby = id
        GROUP BY firstname)
WHERE rnk = 1From a style standpoint, I would suggest that you get in the habit of aliasing your tables in your FROM clause and putting that alias on every column name to make it clear which table a particular column was selected from.
I would also suggest that you come up with a column naming convention that caused the same value to be named the same (or similar) thing in different tables. Joining an ID column from one table to an ENTEREDBY, for example, would be a non-obvious bit of logic. It probably makes more sense to have an EMPLOYEE_ID and an ENTERED_EMPLOYEE_ID column.
Justin

Similar Messages

  • MAX Function Question

    SELECT PatientID,CV_D.ClinicalVitalID,MAX(CV_D.DateTimeTaken)AS DateTimeAdded
    FROM Clinical CV_D
        JOIN ClinicalVital CVG_D on CVG_D.ClinicalVitalID = CV_D.ClinicalVitalID
    WHERE PatientID IN (10024,10028,10025,10026,10027) AND (SystolicBP >= 140) and (DiastolicBP >= 90)
    --GROUP BY PatientID,CV_D.ClinicalVitalID
    Why does this return more than 1 row for each id?  I want 1 row for each 

    DECLARE @table TABLE (PatientID INT, ClinicalVitalID INT, DateTimeTaken DATETIME)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (1,1,CURRENT_TIMESTAMP)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (1,2,CURRENT_TIMESTAMP)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (1,3,CURRENT_TIMESTAMP)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (2,4,CURRENT_TIMESTAMP)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (2,5,CURRENT_TIMESTAMP)
    INSERT INTO @table (PatientID, ClinicalVitalID, DateTimeTaken) VALUES (2,6,CURRENT_TIMESTAMP)
    SELECT PatientID, ClinicalVitalID, MAX(DateTimeTaken) AS DateTimeAdded
    FROM @table
    GROUP BY PatientID, ClinicalVitalID
    This is example code, which is doing the same thing as your current code. Basically, it says, for each unique combination of patientID and ClinicalVitalID, show me the max of the DateTimeTaken column.
    SELECT PatientID, --ClinicalVitalID,
    MAX(DateTimeTaken) AS DateTimeAdded
    FROM @table
    GROUP BY PatientID--, ClinicalVitalID
    Now we've commented out the ClinicalVitalID column, we're asking for the max for each patient.
    Does this resolve your issue?

  • How to call a C function calling a Java Method from another C function ?

    Hi everyone,
    I'm just starting to learn JNI and my problem is that I don't know if it is possible to call a C function calling a Java Method (or doing anything else with JNI) from another C function.
    In fact, after receiving datas in a socket made by a C function, I would like to create a class instance (and I don't know how to do it too ; ) ) and init this instance with the strings I received in the socket.
    Is all that possible ?
    Thank you very much for your help !

    Hard to understand the question, but by most interpretations the answer is going to be yes.
    You do of course understand that JNI is the "API" that sits between Java and C and that every call between the two must go through that. You can't call it directly.

  • How to Avoid Errors in Max Function When Data Contains Blank Cells

    I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
    I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
    So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
    Thanks,
    Nic

    I don't see a problem with "blank" (null string) cells mixed with duration cells.  MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
    A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"?

  • MAX function

    Hi Everyone,
    Am aware of the following flavors of MAX function
    1) choose MAX from the folders/fields list (selected items tab)
    2) create calculation using: MAX keep dense
    3) create calculation using: MAX analytic function
    questions, pls:
    ===========
    a) with MAX regular, MAX keep dense, MAX - analytic function
    is it necessary to sort it using tools/sort - choose fields to sort by?
    or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing
    does MAX keep dense calculation happen during detail row processing?
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
    tx for your ideas and assistance, sandra

    Hi,
    a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
    Rod West

  • Use of MAX function

    Hi,
    I am using parent-child hierarchy and in my reports I want to show Max(hierarchy_level). When I use the function MAX directly in the report it works fine in every way. But I want to have this kind of column in the BI Server presentation catalog so the user does not need to add MAX in Analysis/Answers (this is 11g). Normally this would imply a Max(hierarchy_level) as a logical function, but in the BI Server it is not allowed with MAX function in the logical function so it does not work.
    The hierarchy level is just a column from a dimension table and creating it as a fact column is not a very good solution. I also tried to solve this in many different ways, but only the MAX funtion in Analysis/Answers allways give the correct result. Used in combination with other dimensions etc. I want the exact same behaviour as I get when using MAX in analysis.
    Any good ideas to solve this? Is there another function in the BI Server that works the same way as MAX ?

    Very often, about a primary key, see for example our italian accounting application (our VAT invoices:fatture IVA) ), where the holes might be a problem.
    Yes Rosario, of course I know that, and that's why I said "in this scenario" : if primary key is the only purpose, I don't think holes could be a problem.
    Buona giornata anche a te.

  • How to use MAX() function with date field

    Hi Frzz,
    I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
    I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
    Is there is any other way we can achieve this requirement in Graphical Calculation view??  Your suggestion will really help me.
    Thank  you.
    Krishna.

    Hmm... what have you tried out so far?
    Look, I took the effort and created a little example, just for you
    Assume we have a table that contains the logon dates of users.
    Every line contains the logon date and some info on the user.
    Very much like a not-normalized log file could look like.
    Now, the output we want is: one line per user with the most current logon time.
    Not too difficult:
    1. Have a aggregation node that gives you the distinct user details - one line for every user:
    2. Have another aggregation node that gives you the last (MAX) logon date per user:
    Finally you do a 1:1 join on the USER_ID and map the result to the output.
    Easy as pie
    - Lars

  • Max() function in Data services

    Hi Experts,
         i'm using Data services (etl), and working on budget table(ms sql table),
    1. the table has a field [budget amount] and [version_no],
    2. before i extract the budget amount i need to know the highest version in [version_no] fields
    3. can any body help me on this? i tried to use the script:  ifthenelse(max(version-no),budget_amount, 0) but it retuns error when validation.
    please help me on this:
    thanks in advance
    Archie72

    Hi,
    Connect a Query transform say Query1 from the source table
    Inside Query1
    select MAX(version no) into the output. Do not select the other budget field into the output.
    Connect another Query transform say Query2 from the source table. Connect the output of Query1 also into Query2.
    Inside Query2:
    Join the source table and Query 1 in where
    Query1.version no = SourceTable.version no
    Select version no and budget into Query 2 output and connect it to target table.
    Assuming that the source table has only version number and budget. You might have to tweak and make use of Group By as required where you use the MAX() function. SourceTable mentioned in the where condition will be replaced with your exact source table name
    Regards,
    Suneer

  • MAX function behaving strange...

    I've been researching this for a little bit this morning, and I'm not finding a solution in searching.
    I have a simple problem that I'm sure is an easy fix that I'm overlooking.
    I have a small piece of code where I am trying to return some information out of one table, I want the MAX COMMENT_DATE, and I want to display a few other fields out of that table. When I add in the COMMENT_USER_ID field it seems to ignore the MAX(COMMENT_DATE) function. The results contain duplicate ACCTNUM with different COMMENT_DATEs.
    When I remove the COMMENT_USER_ID from the select statement/group by the MAX function works correctly.
    What am I missing? Thanks for looking...
    1)
    SELECT ACCTNUM, MAX(COMMENT_DATE), COMMENT_CODE, COMMENT_USER_ID
    FROM COMMENTS_TABLE
    WHERE COMMENT_CODE IN ('NEWCOMMENT')
    GROUP BY ACCTNUM, COMMENT_CODE, COMMENT_USER_ID
    This first query will return more than one COMMENT_DATE
    2)
    SELECT ACCTNUM, MAX(COMMENT_DATE), COMMENT_CODE
    FROM COMMENTS_TABLE
    WHERE COMMENT_CODE IN ('NEWCOMMENT')
    GROUP BY ACCTNUM, COMMENT_CODE
    This second query returns only the MAX COMMENT_DATE

    Welcome to the forum!
    The question is: which COMMENT_USER_ID do you want to be displayed along with the max(COMMENT_DATE)?
    SELECT ACCTNUM, MAX(COMMENT_DATE)
    , COMMENT_CODE
    , max(COMMENT_USER_ID) keep (dense_rank last order by COMMENT_DATE)
    FROM COMMENTS_TABLE
    WHERE COMMENT_CODE IN ('NEWCOMMENT')
    GROUP BY ACCTNUM, COMMENT_CODEbye
    TPD

  • MAX Function not returning MAX

    I have a query that is pulling in EDI 214 status codes, and want to pull in the last received status for status type "AG". To do this, I'm using the MAX function on the INSERT_DATE field of the status code AG, but the query keeps returning both AG status codes. I've tried this in a single query (Query 1) but it did not work so I also attempted it in a much smaller query to be used as a subquery, but that still did not work. Can anyone identify what the issue is with what I'm attempting to do?
    Query 1 (All Inclusive):
    SELECT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
    AGSS.EVENTDATE AS AG_EVENT,
    D1SS.EVENTDATE AS D1_EVENT,
    BS.START_TIME AS BUY_START_TIME,
    AGSS.STATUS_CODE_GID AS AG,
    D1SS.STATUS_CODE_GID AS D1,
    BS.DOMAIN_NAME AS BUY_DOMAIN,
    MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE,
    MAX(D1SS.INSERT_DATE) AS D1_INSERT_DATE,
    BS.START_TIME,
    BS.DOMAIN_NAME,
    SHIPSTAT.STATUS_VALUE_GID
    FROM V_ROD_SHIPMENT BS
    INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
    ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
    ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
    INNER JOIN V_ROD_SS_STATUS_HISTORY D1SH
    ON (BS.SHIPMENT_GID = D1SH.SHIPMENT_GID)
    INNER JOIN V_ROD_SHIPMENT_STATUS SHIPSTAT
    ON (BS.SHIPMENT_GID = SHIPSTAT.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS D1SS
    ON D1SH.I_TRANSACTION_NO = D1SS.I_TRANSACTION_NO
    WHERE BS.START_TIME > '18/MAY/12'
    AND BS.DOMAIN_NAME = 'UPS/CP/HDMB'
    AND AGSS.STATUS_CODE_GID = 'AG'
    AND D1SS.STATUS_CODE_GID = 'D1'
    AND (SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
    || '.SECURE RESOURCES_ACCEPTED'
    OR SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
    || '.SECURE RESOURCES_PICKUP NOTIFICATION')
    GROUP BY BS.SHIPMENT_GID,
    AGSS.EVENTDATE,
    D1SS.EVENTDATE,
    BS.START_TIME,
    AGSS.STATUS_CODE_GID,
    D1SS.STATUS_CODE_GID,
    BS.DOMAIN_NAME,
    SHIPSTAT.STATUS_VALUE_GID
    Query 2 (to be used as a sub-query if I cannot pull MAX insert date in previous query):
    SELECT DISTINCT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
    AGSS.EVENTDATE AS AG_EVENT,
    AGSS.STATUS_CODE_GID AS AG,
    MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE
    FROM V_ROD_SHIPMENT BS
    INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
    ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
    ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
    WHERE AGSS.STATUS_CODE_GID = 'AG'
    AND BS.SHIPMENT_GID = 'UPS/CP/HDMB.HDM-1000203768'
    GROUP BY BS.SHIPMENT_GID,
    AGSS.EVENTDATE,
    AGSS.STATUS_CODE_GID
    Results of query 2 (similar issue as query 1, query doesn't return MAX insert date):
    BUY_SHIPMENT_GID     AG_EVENT     AG     AG_INSERT_DATE
    UPS/CP/HDMB.HDM-1000203768     5/25/2012 6:00:00 PM     AG     5/21/2012 3:10:36 PM
    UPS/CP/HDMB.HDM-1000203768     6/1/2012 5:00:00 PM     AG     5/20/2012 2:36:18 PM
    I appreciate any help.
    Thanks,
    -Adam

    Hi, Adam,
    Welcome to the forum!
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    If you can show what the problem is using commonly available tables (such as those in the scott schem) then you don't have to psot any sample data; just the results and the explanation.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    MAX (insert_date) returns the latest insert_date. I think, in this problem, you don't really want the latest insert_date; you want the status code that's related to the last insert_date. One way to get that is the aggregate FIRST (or LAST) function.
    Consider this query, using the scott.emp table:
    SELECT       ename
    ,       hiredate
    FROM       scott.emp
    ORDER BY  hiredate
    ,            ename
    ;Output:
    ENAME      HIREDATE
    SMITH      17-Dec-1980
    ALLEN      20-Feb-1981
    WARD       22-Feb-1981
    JONES      02-Apr-1981
    BLAKE      01-May-1981
    CLARK      09-Jun-1981
    TURNER     08-Sep-1981
    MARTIN     28-Sep-1981
    KING       17-Nov-1981
    FORD       03-Dec-1981
    JAMES      03-Dec-1981
    MILLER     23-Jan-1982
    SCOTT      19-Apr-1987
    ADAMS      23-May-1987Say we're only interested in seeing the last hiredate, and the name of the person hired on that date:
    LAST_ENAME LAST_HIREDA
    ADAMS      23-May-1987Here's how to get those results using the aggregate LAST function:
    SELECT       MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
    ,       MAX (hiredate)                                              AS last_hiredate
    FROM       scott.emp
    ;What if there's a tie for the latest hiredate? For example, say we're only looking at people hired before 1982. In that case, the latest hiredate is December 3, 1981, and there happen to be two people hired on that date. This query
    SELECT       MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
    ,       MAX (hiredate)                                              AS last_hiredate
    FROM       scott.emp
    WHERE         hiredate     < DATE '1982-01-01'
    ;produces only 1 row of output:
    LAST_ENAME LAST_HIREDA
    FORD       03-Dec-1981Why did it show FORD rather than JAMES? Because of the MIN function. When there happens to be a tie for the latest hiredate, MIN says to return the first ename (in normal sort order) of the rows that have that hiredate.
    FIRST and LAST work with GROUP BY, too.
    In the example above, we were only looking at one column related to the latest hiredate. If we neede to see several columns, it would be simpler to use the analytic ROW_NUMBER function:
    WITH     got_r_num     AS
         SELECT  emp.*
         ,     ROW_NUMBER () OVER ( ORDER BY  hiredate  DESC
                                   ,            ename
                           ) AS r_num
         FROM    scott.emp
         WHERE     hiredate     < DATE '1982-01-01'
    SELECT     *
    FROM     got_r_num
    WHERE     r_num     = 1
    I hope this answers your question.
    If not, post a more complete explanation of what you want to do. if you have to use your own tables, then post CREATE TABLE and INSERT statements for a little sample data. Post the results you want from that data, and explain how you get those results from that data.

  • Max Function doesn

    i have created a procedure in a form that return summary columns (count,max) and it is based in a view which is created containing 2 select statement. the problem is the max function doesn't return the max date in the first select statment in the Form. but if i run it in sql it does. i think the trouble is because this feild is a companition of two feilds(contract_Date and sysdate) ... i will add the view and the procedure below so it would be clear. but my question is : if the sql return the right result why the form can't show it.
    View ...
    CREATE OR REPLACE VIEW ATN_DLEV_DCON_VIEW( EMP_ID,
    REPORT,TYPE, DATE_FROM )
    AS SELECT
    ID,
    'TO_RENEW' REPORT,
    'ÊÌÏíÏ ÚÞÏ' TYPE,
    CONTRACT_DATE DATE_FROM
    FROM PRS_EMPLOYEE_PROFILE
    WHERE TO_CHAR(ADD_MONTHS(SYSDATE,1),'MM')=TO_CHAR(EMPLOYMENT_DATE,'MM')
    AND CONTRACT_TYPE = 2
    AND EMP_STS_ID NOT IN (40, 28)
    union
    SELECT
    EMP_ID,
              'PayLev01'     REPORT ,
              'ÊÑÍíá ÅÌÇÒÉ'     TYPE,
    START_DATE     DATE_FROM
         FROM PRS_EMP_VAC_APPLICANTS
         WHERE REC_STATUS in (1,5) and emp_id <> 187
    Procedure
    PROCEDURE P_SHOW_TASKS IS
         V_COUNT          NUMBER:=0;
         V_CHK               NUMBER;
    BEGIN
    SELECT COUNT(EMP_ID)
         INTO V_CHK
         FROM SEC_USERS
         WHERE ID = :GLOBAL.USR;
    IF V_CHK <> 0 THEN
         SELECT DES_ARB
         INTO :TASKS.DEPT_NAME
         FROM           PRS_DEPARTMENTS
         WHERE ID = 6 ;
         SELECT COUNT(DISTINCT TYPE)
              INTO V_COUNT
              FROM ATN_DLEV_DCON_VIEW1, SEC_GROUPS
              WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) AND ID = 'ADM';
         IF V_COUNT <> 0 THEN
              SHOW_VIEW('CV_TASKS');
              GO_BLOCK('TASKS');
              FIRST_RECORD;               
              FOR I IN (SELECT report, COUNT(EMP_ID) COUNT, TYPE, MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) GROUP BY REPORT, TYPE) LOOP
                   :TASKS.REPORT := I.REPORT;
                   :TASKS.COUNT := I.COUNT;     
                   :TASKS.TYPE := I.TYPE;
                   :TASKS.MAX_DATE := I.DATE_FROM;
                   V_COUNT := V_COUNT - 1;
                   IF V_COUNT <> 0 THEN
                        NEXT_RECORD;
                   ME(V_COUNT);
                   END IF;
              END LOOP;
         END IF;
    ELSE
         SELECT COUNT(DISTINCT TYPE)
              INTO V_COUNT
              FROM ATN_DLEV_DCON_VIEW1;
         IF V_COUNT <> 0 THEN
              SHOW_VIEW('CV_TASKS');
              go_block('TASKS');
              FIRST_RECORD;     
              FOR I IN (SELECT REPORT, COUNT(EMP_ID) COUNT, TYPE , MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 GROUP BY REPORT, TYPE) LOOP
                   :TASKS.REPORT := I.REPORT;
                   :TASKS.COUNT := I.COUNT;          
                   :TASKS.TYPE := I.TYPE;
                        :TASKS.MAX_DATE := I.DATE_FROM;
                   V_COUNT := V_COUNT - 1;
                   IF V_COUNT <> 0 THEN
                        NEXT_RECORD;
                   ME(V_COUNT);
                   END IF;
              END LOOP;
         END IF;
    END IF;
    END;

    thank you for your reply ...well, this is what is confusing me, it works in sql and it works in forms as well but not with the two date variables (To_RENEW, START_DATE)... if you had a look to the view, i posted the wrong one here but down below will be the one i am using. in the first select statment the date is a companition of CONTRACT_DATE
    (to get the month and day of renewal date of the contract because i don't have it as a COLOUM in the table ) concatonated with sysdate to get only the year "IT IN BOLD IN THE VIEW" and in the second select statment it is availabe in the table, and it is returned correclty in sql and procedure of the form as well. so if there is something worng with procedure the other date will not be shown this is the part of the procedure that fill the form with data
    (SELECT report, COUNT(EMP_ID) COUNT, TYPE, MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) GROUP BY REPORT, TYPE) LOOP
    :TASKS.REPORT := I.REPORT;
    :TASKS.COUNT := I.COUNT;
    :TASKS.TYPE := I.TYPE;
    :TASKS.MAX_DATE := I.DATE_FROM;
    V_COUNT := V_COUNT - 1;
    IF V_COUNT <> 0 THEN
    NEXT_RECORD;
    this part ( MAX(DATE_FROM) works with the second select statment of the view and it doen't work for the first one in the form only but it does in sql foe both
    i am waitin 4 ur eply
    here is the right view
    CREATE OR REPLACE VIEW ATN_DLEV_DCON_VIEW( EMP_ID,
    REPORT,TYPE, DATE_FROM )
    AS SELECT
    ID,
    'TO_RENEW' REPORT,
    'ÊÌÏíÏ ÚÞÏ' TYPE,
    TO_CHAR(SYS_DATE,'YYYY') || '/'|| TO_CHAR(CONTRACT_DATE,'MM','DD')DATE_FROM
    FROM PRS_EMPLOYEE_PROFILE
    WHERE TO_CHAR(ADD_MONTHS(SYSDATE,1),'MM')=TO_CHAR(EMPLOYMENT_DATE,'MM')
    AND CONTRACT_TYPE = 2
    AND EMP_STS_ID NOT IN (40, 28)
    union
    SELECT
    EMP_ID,
    'PayLev01' REPORT ,
    'ÊÑÍíá ÅÌÇÒÉ' TYPE,
    START_DATE DATE_FROM
    FROM PRS_EMP_VAC_APPLICANTS
    WHERE REC_STATUS in (1,5) and emp_id <> 187

  • XPath max function

    Hi all,
    I'm a beginner working with XPath expressions.
    I have a xml document 'test.xml' with the following contents.
    <?xml version="1.0" encoding="UTF-8"?>
    <ICRI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.orswegimoarmada.es/ORSWE/ICRI
    http://www.orswegimoarmada.es/ORSWE/XSD/ICRI/ICRI.xsd"
    xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI">
    <ID>ICRI.Prueba.DocPrueba1.2006.11.15-09.19.01</ID>
    <NombreRecurso>DocPrueba1</NombreRecurso>
    <TipoRecurso>Documento Técnico</TipoRecurso>
    <Descripcion>Documento de ejemplo.</Descripcion>
    <ExtensionRecurso/>
    <VersionRecurso>1.0</VersionRecurso>
    <Estado>En Proceso</Estado>
    <NivelSeguridad>NATO UNCLASSIFIED</NivelSeguridad>
    <Entornos/>
    <PalabrasClave/>
    <Sinonimos/>
    <Modificaciones>
    <Modificacion>
    <Usuario>demoadminpro</Usuario>
    <FechaHora>2006.11.15-09.19.01</FechaHora>
    <Secuencia>1</Secuencia>
    <EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.19.01.xml</EnlaceRecurso>
    </Modificacion>
    <Modificacion>
    <Usuario>demoadminpro</Usuario>
    <FechaHora>2006.11.15-09.20.01</FechaHora>
    <Secuencia>2</Secuencia>
    <EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.20.01.xml</EnlaceRecurso>
    </Modificacion>
    <Modificacion>
    <Usuario>demoadminpro</Usuario>
    <FechaHora>2006.11.15-09.21.01</FechaHora>
    <Secuencia>3</Secuencia>
    <EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.21.01.xml</EnlaceRecurso>
    </Modificacion>
    </Modificaciones>
    </ICRI>
    I use the code to obtain information about xml.
    SELECT extractValue(value(d), '/ICRI/NombreRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') NOMBRERECURSO,
           extractValue(value(d), '/ICRI/TipoRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') TIPORECURSO,
            extractValue(value(d), '/ICRI/VersionRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') VERSIONRECURSO,
            extractValue(value(d), '/ICRI/Descripcion', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') DESCRIPCION,
            extractValue(value(d), '/ICRI/Modificaciones/Modificacion/Secuencia', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') SECUENCIA
    FROM RESOURCE_VIEW r, table(xmlsequence(extract(r.res, '/r:Resource/r:Contents/i:ICRI', 'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd" xmlns:i="http://www.orswegimoarmada.es/ORSWE/ICRI"'))) d
    WHERE r.any_path='test.xml'But the element Secuencia has several values and I only need to obtain the max of this values. I think, XPath max function can resolve this issue, but I don't know how do I do this?. Is it possible?
    Thanks in advance,
    David.

    Well, I am desperate :-(((
    I am trying to extend the early query, now, r.any_path must be obtained from another table that it is another registered schema also.
    The folowing is a piece of this query:
    SELECT
    extractValue(value(di), '/ICRI/NombreRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') NOMBRERECURSO,
    extractValue(value(di), '/ICRI/TipoRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') TIPORECURSO,
    extractValue(value(di), '/ICRI/VersionRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') VERSIONRECURSO,
    extractValue(value(di), '/ICRI/Descripcion', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') DESCRIPCION
    FROM RESOURCE_VIEW r,
         table(xmlsequence(extract(r.res, '/r:Resource/r:Contents/i:ICRI', 'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd" xmlns:i="http://www.orswegimoarmada.es/ORSWE/ICRI"'))) di
    WHERE
        r.any_path IN 
        (select extractValue(value(t), '/InfoEntradaGeneral/EnlaceICRI', 'xmlns="http://www.orswegimoarmada.es/ORSWE/PlantillaProyecto')
         FROM PLANTILLAPROYECTO p, table(xmlsequence(extract(p.object_value, '/PlantillaProyecto/Proceso/Pasos/Paso[@IdPaso="0"]/Actividades/Actividad[@IdActividad="1"]/EntradasActividad/EntradasGenerales/InfoEntradaGeneral'))) t
         WHERE existsNode(p.object_value, '/PlantillaProyecto/DetallesProyecto[NombreProyecto="Prueba"]')=1);Now, Oracle only shows me a register when the query must be three.
    The query
    select extractValue(value(t), '/InfoEntradaGeneral/EnlaceICRI', 'xmlns="http://www.orswegimoarmada.es/ORSWE/PlantillaProyecto')
    FROM PLANTILLAPROYECTO p, table(xmlsequence(extract(p.object_value, '/PlantillaProyecto/Proceso/Pasos/Paso[@IdPaso="0"]/Actividades/Actividad[@IdActividad="1"]/EntradasActividad/EntradasGenerales/InfoEntradaGeneral'))) t
    WHERE existsNode(p.object_value, '/PlantillaProyecto/DetallesProyecto[NombreProyecto="Prueba"]')=1);returns several values, for instance:
    1. test.xml
    2. test1.xml
    3. test2.xml
    Why does not it work?. I suppose that the query is correct.
    I try the same with relational tables and it works fine.
    Query SELECT B.COLUMN2 FROM B WHERE B.COLUMN1 IN (SELECT COLUMN1 FROM A returns several values from A and shows the right values from B.
    Please, Could someone to help me?
    Thanks in advance,
    David.

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Regarding MAX() function

    Hi,
    I am having table A. I have few records in the table A. Database version : 9.2
    ID name deleted
    2 XYZ N
    3 ABD N
    4 GJK N
    5 GJK N
    6 HGY N
    7 YJG N
    8 PIN N
    9 BMF N
    10 OLG N
    I used the following query...
    SELECT MAX(ID) FROM A WHERE DELETED='N';
    It was worked fine until now....
    Now i used the same query...
    But the result is
    MAX(ID)
    9
    Please help me... What is the reason?
    I want the correct result...
    Thanks in advance....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Kamran Agayev A. wrote:
    Yes you can use TO_NUMBER inside MAX function and it will not give any error in the futureHave you tested it?
    SQL> create table a (id,name,deleted)
      2  as
      3  select '2', 'XYZ', 'N' from dual union all
      4  select '3', 'ABD', 'N' from dual union all
      5  select '4', 'GJK', 'N' from dual union all
      6  select '5', 'GJK', 'N' from dual union all
      7  select '6', 'HGY', 'N' from dual union all
      8  select '7', 'YJG', 'N' from dual union all
      9  select '8', 'PIN', 'N' from dual union all
    10  select '9', 'BMF', 'N' from dual union all
    11  select '10', 'OLG', 'N' from dual
    12  /
    Tabel is aangemaakt.
    SQL> select max(id)
      2    from a
      3   where deleted = 'N'
      4  /
    MA
    9
    1 rij is geselecteerd.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
                        MAX(TO_NUMBER(ID))
                                        10
    1 rij is geselecteerd.
    SQL> insert into a values ('2A', 'ABC', 'N')
      2  /
    1 rij is aangemaakt.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
    select max(to_number(id))
    FOUT in regel 1:
    .ORA-01722: invalid numberRegards,
    Rob.

  • Use of MAX function in Query Designer

    Dear all,
    i want to create a report that gives ONE line per period that holds the MAX of several lines per period. So NO addition of the KF but just one line item.
    I tried to use the MAX function and/or MAX drop-down boxes via properties on KF,
    but they all provide the wrong result (mostly the MAX after summaction of the KF).
    Any ideas ??
    Greetz,
    Herman

    Hi Herman
        Please check the KF infoobject property which might have been set to Summation.  You need to change the property of the KF to MAX if you wish to have MAX value. 
        Hope this might be helpful to you
    Thanks
    Kishore Kusupati

Maybe you are looking for

  • Apple claims Netflix needs to Update

    I just completed my Apple Tech call this morning:  it took 65min to eventually hear Apple blame Netflix as cause of problem and nothing could be done on Apple's end -- no foreseeable OS update to resolve the issue -- and actually suggests that Netfli

  • ITunes Constantly Turns Shuffle Back On

    Since upgrading to iTunes 9, shuffle continuously turns itself on. If I turn it off again and play a song, it will reset once that song finishes. How can I fix this?

  • Payment transfer program with PSCD

    Hi, The payment transfer program works if we use FIAP But when pay vendor invoices through the process of PSCD we have the status paid but we don't see which vendor invoices have been paid. Does the program works normally with PSCD Best regards Salva

  • Roles and authorization

    Hello We are having a problem in the roles in which the user is not able to acess the reports. We checked on the trace and find out the user is not having authorzation to the info cube which is sending data to the report. But the user never had this

  • Memory issues...what is the "Other" that is taking up so much space?

    I have a 4 Gig IPhone...and have 303mb of music, 1.3 gigs of video, 25.2 mb of photos, and then there is the 1.61 GB of "Other" ???...what is taking up all this space ? any idea...or anyone else notice that goin on with there Iphone ???...Large amoun