How I can change this query

How I can change this query, I got it from someone on the list, and it works just fine, Thank you! but I can not hardcode the data, the data is actually in a repiting table
SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY, SARAPPD_APPL_NO 1 SARAPPD_SEQ_NO
We can have a person with one record another one with two or three, we just don't know, each record have a sequence number SARAPPD_SEQ_NO
this SARAPPD_PIDM = 2232040 with will a paramater pass to the function (SARAPPD_PIDM = p_pidm)
excuse my ignorance, but I just don't have experience with this kind of queries..
with t as ( -- sample data
    select 2232040     SARAPPD_PIDM,  200990 SARAPPD_TERM_CODE_ENTRY, 1 SARAPPD_APPL_NO, 1 SARAPPD_SEQ_NO,   to_date('12/03/2008','mm/dd/yyyy') sARAPPD_APDC_DATE,  'S*'     SARAPPD_APDC_CODE from dual union all
    select 2232040     ,200990     ,1    ,2     ,to_date('12/08/2008','mm/dd/yyyy'),     'D1' from dual union all
    select 2232040     ,200990     ,1    ,3    ,to_date('03/18/2009','mm/dd/yyyy'),  'S*'  from dual union all
    select 2232040    ,200990     ,1    ,4     ,to_date('03/29/2009','mm/dd/yyyy')     ,'WL' from dual union all
    select 2232040    ,200990     ,1    ,4     ,to_date('03/27/2009','mm/dd/yyyy')     ,'WL' from dual
    ) -- end sample data
    SELECT * FROM (
    SELECT
   A.SARAPPD_PIDM,
   A.SARAPPD_APDC_CODE,
   A.sarappd_apdc_date,
   ROW_NUMBER() OVER (PARTITION BY SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY ORDER BY SARAPPD_APDC_DATE
   DESC) row_num
   ,lead (SARAPPD_APDC_DATE,1) over (ORDER BY SARAPPD_APDC_DATE) AS next_date
   FROM t A
   where
    SARAPPD_PIDM = 2232040
     AND sarappd_apdc_code IN ('SA', 'FA', 'S-', 'F-', 'RF', 'F*','AD', 'W-', 'R2', 'S*', 'HF', 'WL','HD', 'R1', 'HS', 'D2', 'W+')
   where  next_date >= to_date('3/27/2009','mm/dd/yyyy');Edited by: user648177 on May 1, 2009 8:52 AM

Thank you
I am getting this result
SARAPPD_PIDM     SARAPPD_APDC_CODE              SARAPPD_APDC_DATE     SARADAP_ADMT_CODE     ROW_NUM               NEXT_DATE
2232040                                   S*            12/03/2008 16:30:45     D1                                    3                  03/18/2009 08:58:06
2232040                                   S*            03/18/2009 08:58:06     D1                                      2                 03/21/2009 13:53:23I only want to retrieve the one with the max date ( 03/18/2009 08:58:06)
I try to add the
and SARAPPD_SEQ_NO = (select max(b.SARAPPD_SEQ_NO)
                               from SARAPPD b
                               where SARAPPD_pidm = b.SARAPPD_pidm)
{code}
{code}
but it did not work
{code}
SELECT *
  FROM (SELECT A.SARAPPD_PIDM,
               A.SARAPPD_APDC_CODE,
               A.sarappd_apdc_date,
               saradap_admt_code,
               ROW_NUMBER() OVER(PARTITION BY SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY ORDER BY SARAPPD_APDC_DATE DESC) row_num,
               lead(SARAPPD_APDC_DATE, 1) over(ORDER BY SARAPPD_APDC_DATE) AS next_date
          FROM saturn.sarappd A, SARADAP
         where SARAPPD_PIDM = 2232040
           and SARADAP_PIDM = SARAPPD_PIDM
           AND saradap_term_code_entry = SARAPPD_TERM_CODE_ENTRY
           AND SARADAP_APPL_NO = A.SARAPPD_APPL_NO
           --         and SARAPPD_SEQ_NO = (select max(b.SARAPPD_SEQ_NO)
            --                    from SARAPPD b
            --                    where SARAPPD_pidm = b.SARAPPD_pidm)
           AND sarappd_apdc_code IN
               ('SA', 'FA', 'S-', 'F-', 'RF', 'F*', 'AD', 'W-', 'R2', 'S*', 'HF', 'WL', 'HD', 'R1', 'HS', 'D2', 'W+'))
Where next_date <=       saturn_midd.utlq.f_get_adm_freeze_date(saradap_admt_code)
{code}
i now that if I add and row_num=2 it will work, but this is just an example I don't know the row_num of all the records
Edited by: user648177 on May 4, 2009 5:57 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How I can change this query, so I can display the name and scores in one r

    How I can change this query, so I can add the ID from the table SPRIDEN
    as of now is giving me what I want:
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20in one line but I would like to add the id and name that are stored in the table SPRIDEN
    SELECT sortest_pidm,
           max(decode(rn,1,sortest_tesc_code)) tesc_code1,
           max(decode(rn,1,score)) score1,
           max(decode(rn,2,sortest_tesc_code)) tesc_code2,
           max(decode(rn,2,score)) score2,
           max(decode(rn,3,sortest_tesc_code)) tesc_code3,
           max(decode(rn,3,score))  score3,
           max(decode(rn,4,sortest_tesc_code)) tesc_code4,
           max(decode(rn,4,score))  score4,
           max(decode(rn,5,sortest_tesc_code)) tesc_code5,
           max(decode(rn,5,score))  score5,
           max(decode(rn,6,sortest_tesc_code)) tesc_code6,
           max(decode(rn,6,score))  score6        
      FROM (select sortest_pidm,
                   sortest_tesc_code,
                   score,
                  row_number() over (partition by sortest_pidm order by score desc) rn
              FROM (select sortest_pidm,
                           sortest_tesc_code,
                           max(sortest_test_score) score
                      from sortest,SPRIDEN
                      where
                      SPRIDEN_pidm =SORTEST_PIDM
                    AND   sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
                     and  sortest_pidm is not null 
                    GROUP BY sortest_pidm, sortest_tesc_code))
                    GROUP BY sortest_pidm;
                   

    Hi,
    That depends on whether spriden_pidm is unique, and on what you want for results.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
    If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
    Either way, explain how you get those results from that data.
    Always say which version of Oracle you're using.
    It looks like you're doing something similiar to the following.
    Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
    DEPTNO DNAME          LOC           JOB_1   SAL_1 JOB_2   SAL_2 JOB_3   SAL_3
        20 RESEARCH       DALLAS        ANALYST  3000 MANAGER  2975 CLERK    1100
        10 ACCOUNTING     NEW YORK      MANAGER  2450 CLERK    1300
        30 SALES          CHICAGO       MANAGER  2850 CLERK     950On each row, the jobs are listed in order by the highest salary.
    This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
    It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
    SELECT    deptno
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno
                                              ORDER BY          max_sal     DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno
                       ,           e.job
    GROUP BY  deptno
    ;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
    SELECT    deptno, dname, loc                    -- Changed
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno, dname, loc          -- Changed
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno      -- , dname, loc     -- Changed
                                              ORDER BY          max_sal      DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
    GROUP BY  deptno, dname, loc                    -- Changed
    ;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
    By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
    SELECT    deptno, dname, loc
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
                   SELECT    e.deptno, d.dname, d.loc
              ,       e.job
              ,       MAX (e.sal)     AS max_sal
              ,       ROW_NUMBER () OVER ( PARTITION BY  e.deptno
                                           ORDER BY       MAX (sal)     DESC
                                          )       AS rn
              FROM      scott.emp    e
              ,       scott.dept   d
              WHERE     e.deptno        = d.deptno
              AND       e.job                IN ('ANALYST', 'CLERK', 'MANAGER')
                  GROUP BY  e.deptno, d.dname, d.loc
              ,       e.job
    GROUP BY  deptno, dname, loc
    ;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature.

  • How I can change this query to generate a sequence

    This query
    select
    SZSTCLA_PIDM,
      SZSTCLA_TERM_CODE,
      SZSTCLA_LAST_NAME
      from SZSTCLA,SHRTGPA
    where SZSTCLA_PIDM IN ( 120125,186114)
    AND SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE
    AND  shrtgpa_pidm  = SZSTCLA_PIDM
      AND SZSTCLA_RECORDED_EARNED_CRED > 0
      ORDER BY SZSTCLA_TERM_CODE returns the following results
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME
    186114     198810     Johnson
    186114     198820     Johnson
    186114     198910     Johnson
    186114     198920     Johnson
    186114     199010     Johnson
    186114     199020     Johnson
    186114     199110     Johnson
    186114     199120     Johnson
    120125     200720     Smith
    120125     200810     Smith
    120125     200820     Smith
    120125     200910     Smith
    120125     200920     Smith
    120125     201010     Smith
    120125     201020     Smith
    120125     201110     Smith
    120125     201120     SmithNotice that breaks in every szstcla_pidm, I need to modify the query, so it can display a number sequence for each SZSTCLA_TERM_CODE
    so it will be like
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                    seq
    186114                     198810                                     Johnson                         1
    186114                     198820                                     Johnson                         2
    186114                    198910                                     Johnson                         3
    186114                    198920                                     Johnson                         4
    186114                    199010                                     Johnson                         5
    186114                    199020                                     Johnson                         6
    186114                    199110                                     Johnson                         7
    186114                    199120                                     Johnson                         8 then
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                      seq
    120125                  200720                                   Smith                             1
    120125                  200810                                    Smith                             2
    120125                  200820                                   Smith                              3
    120125                  200910                                   Smith                              4
    120125                  200920                                   Smith                              5
    120125                  201010                                   Smith                              6
    120125                  201020                                   Smith                              7
    120125                  201110                                   Smith                              8
    120125                  201120                                   Smith                              9

    here are the insert scripts,I slighthly change the name of the tables(the tables are already in the DB)
    create table SZSTCLT
    SZSTCLT_PIDM NUMBER(8),
    SZSTCLT_TERM_CODE VARCHAR2(8),
    SZSTCLT_LAST_NAME VARCHAR2(30)
    create table SHRTGPT
    SHRTGPT_PIDM NUMBER(8),
    SHRTGPT_TERM_CODE VARCHAR2(8)
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '198810','Johnson' FROM DUAL;   
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '198820','Johnson' FROM DUAL;   
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '198910','Johnson' FROM DUAL;   
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '198920','Johnson' FROM DUAL;   
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '199010','Johnson' FROM DUAL; 
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '199020','Johnson' FROM DUAL;  
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '199110','Johnson' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 186114, '199120','Johnson' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 120125,'200920','Smith' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 120125,'201010','Smith' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 120125,'201020','Smith' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 120125,'201110','Smith' FROM DUAL;
    INSERT INTO SZSTCLT( SZSTCLT_PIDM, SZSTCLT_TERM_CODE,SZSTCLT_LAST_NAME) SELECT 120125,'201120','Smith' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 120125, '200920' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 120125, '201010' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 120125, '201020' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 120125, '201110' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 120125, '201120' FROM DUAL;
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '198810' FROM DUAL; 
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '198820' FROM DUAL;  
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '198910' FROM DUAL;    
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '198920' FROM DUAL;    
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '199010' FROM DUAL;  
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '199020' FROM DUAL; 
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '199110' FROM DUAL; 
    INSERT INTO SHRTGPT(SHRTGPT_PIDM,SHRTGPT_TERM_CODE) SELECT 186114, '199120' FROM DUAL;   This query
    select
    SZSTCLT_PIDM,
      SZSTCLT_TERM_CODE,
      SZSTCLT_LAST_NAME,
      row_number() over (partition by  SZSTCLT_PIDM, SZSTCLT_TERM_CODE order by  SZSTCLT_PIDM,SZSTCLT_TERM_CODE)   seq
      from SZSTCLT,SHRTGPT
    where SZSTCLT_PIDM IN ( 120125,186114)
    AND SHRTGPT_TERM_CODE = SZSTCLT_TERM_CODE
    AND  SHRTGPT_PIDM  = SZSTCLT_PIDM
    -- AND SZSTCLA_RECORDED_EARNED_CRED > 0
    ORDER BY SZSTCLT_PIDM,SZSTCLT_TERM_CODE is generating this output
    120125     201020     Smith     1
    120125     201110     Smith     1
    120125     201120     Smith     1
    186114     198810     Johnson     1
    186114     198820     Johnson     1
    186114     198910     Johnson     1
    186114     198920     Johnson     1
    186114     199010     Johnson     1
    186114     199020     Johnson     1
    186114     199110     Johnson     1
    186114     199120     Johnson     1 I want something like this
    120125     201020     Smith     1
    120125     201110     Smith     2
    120125     201120     Smith     3
    186114     198810     Johnson     1
    186114     198820     Johnson     2
    186114     198910     Johnson     3
    186114     198920     Johnson     4
    186114     199010     Johnson     5
    186114     199020     Johnson     6
    186114     199110     Johnson     7
    186114     199120     Johnson     8 Edited by: 893973 on Sep 15, 2012 6:52 PM

  • How I can change this query? to get the results I want

    This query
    select
    SHRTGPA_pidm,
    SZSTCLA_TERM_CODE,
    SHRTGPA_GPA_HOURS
    from  szstcla,SHRTGPA
    where szstcla_pidm = 74246
    and SHRTGPA_pidm = szstcla_pidm
    and SZSTCLA_TERM_CODE <> SZSTCLA_TERM_CODE_MATRIC
    and SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODEreturns
    74246     201020     4
    74246     201120     4
    74246     201110     4
    74246     201210     4
    74246     201220     4 I want to aggregate so the query will return
    74246 201020     4
    74246 201120     8
    74246 201110     12
    74246 201210     16201220     20

    Hi,
    So, instead of shrtgpa_gpa_hours, you want a cumulative total of shrtgpa_gpa_hours, adding up all the previous values.
    That's a job for the analytic SUM function:
    select
    SHRTGPA_pidm,
    SZSTCLA_TERM_CODE,
    SUM (SHRTGPA_GPA_HOURS) OVER (ORDER BY x)  as running_shrtgpa_gpa_hours     -- *****  CHANGED  *****
    from  szstcla,SHRTGPA
    where szstcla_pidm = 74246
    and SHRTGPA_pidm = szstcla_pidm
    and SZSTCLA_TERM_CODE  SZSTCLA_TERM_CODE_MATRIC
    and SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODEwhere x is the expression (or list of expressions) that determines what are the "previous" rows.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • How I can change this query to retun both records (max scores)

    This query does not retrieve records when I have two records for the same pidm (unique key) with the same score and different test date
    SORTEST_PIDM IS 'This field identifies the internal identification number of the student.'
       SELECT sortest_pidm,
                 CASE sortest_tesc_code WHEN 'S02' THEN 'S06' END CASE,
                 sortest_tsrc_code,
                 test_date,
                 sortest_test_score
                   FROM (SELECT a.*,
                         ROW_NUMBER ()
                         OVER (
                            PARTITION BY a.sortest_tesc_code, a.sortest_pidm
                            ORDER BY
                               a.sortest_test_score DESC,
                               a.sortest_test_date DESC)
                            rn
                    FROM sortest a
                   WHERE ---  a.sortest_pidm = 228709
                      -- sortest_pidm  =  107168
                      ---- sortest_pidm  =  30021 --
                     and    a.sortest_tesc_code = 'S02'
                         AND a.sortest_tsrc_code NOT IN ('SUPR'))
           WHERE rn = 1;like this one
    SORTEST_PIDM     SORTEST_TESC_CODE        SORTEST_TEST_DATE     SORTEST_TEST_SCORE     
    30037                      S02                        03/01/2010 00:00:00     630     
    30037                      S02                         05/01/2010 00:00:00     630      It retrieves data when the scores are different
    like this one
    SORTEST_PIDM     SORTEST_TESC_CODE        SORTEST_TEST_DATE     SORTEST_TEST_SCORE
    107168                      S02                                        06/01/2010 00:00:00         690
    107168                      S02                                        10/01/2010 00:00:00     800I need to be able to return the maximun test scrore in both cases...
    here is some code to create a test table and insert the codes, I took out the sortest the table is already in the DB, I called the test table test...
        CREATE TABLE TEST
       TEST_PIDM             NUMBER(8)            NOT NULL,
       TESC_CODE        VARCHAR2(4 CHAR)     NOT NULL,
       TEST_DATE        DATE                 NOT NULL,
       TEST_SCORE       VARCHAR2(5 CHAR)     NOT NULL
       insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select    30037,'S02',to_date('03/01/2010','mm/dd/yyyy'),'630' from dual ;
        insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select    30037,'S02',to_date('05/01/2010','mm/dd/yyyy'),'630' from dual ;
       insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select      107168 ,'S02',to_date('06/01/2010','mm/dd/yyyy'),'690' from dual ;
        insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select      107168 ,'S02',to_date('10/01/2010','mm/dd/yyyy'),'800' from dual;
      

    Hi,
    893973 wrote:
    This query does not retrieve records when I have two records for the same pidm (unique key) with the same score and different test date
    SORTEST_PIDM IS 'This field identifies the internal identification number of the student.'
    SELECT sortest_pidm,
    CASE sortest_tesc_code WHEN 'S02' THEN 'S06' END CASE,
    sortest_tsrc_code,
    test_date,
    sortest_test_score
    FROM (SELECT a.*,
    ROW_NUMBER ()
    OVER (
    PARTITION BY a.sortest_tesc_code, a.sortest_pidm
    ORDER BY
    a.sortest_test_score DESC,
    a.sortest_test_date DESC)
    rn
    FROM sortest a
    WHERE ---  a.sortest_pidm = 228709
    -- sortest_pidm  =  107168
    ---- sortest_pidm  =  30021 --
    and    a.sortest_tesc_code = 'S02'
    AND a.sortest_tsrc_code NOT IN ('SUPR'))
    WHERE rn = 1;like this one
    SORTEST_PIDM     SORTEST_TESC_CODE        SORTEST_TEST_DATE     SORTEST_TEST_SCORE     
    30037                      S02                        03/01/2010 00:00:00     630     
    30037                      S02                         05/01/2010 00:00:00     630      It retrieves data when the scores are different
    like this one
    SORTEST_PIDM     SORTEST_TESC_CODE        SORTEST_TEST_DATE     SORTEST_TEST_SCORE
    107168                      S02                                        06/01/2010 00:00:00         690
    107168                      S02                                        10/01/2010 00:00:00     800I need to be able to return the maximun test scrore in both cases...
    here is some code to create a test table and insert the codes, I took out the sortest the table is already in the DB, I called the test table test... It looks like you renamed all the columns, too, making the query above useless. There's no danger in using the same column names in two or more tables, even in the same schema.
    CREATE TABLE TEST
    TEST_PIDM             NUMBER(8)            NOT NULL,
    TESC_CODE        VARCHAR2(4 CHAR)     NOT NULL,
    TEST_DATE        DATE                 NOT NULL,
    TEST_SCORE       VARCHAR2(5 CHAR)     NOT NULL
    insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select    30037,'S02',to_date('03/01/2010','mm/dd/yyyy'),'630' from dual ;
    insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select    30037,'S02',to_date('05/01/2010','mm/dd/yyyy'),'630' from dual ;
    insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select      107168 ,'S02',to_date('06/01/2010','mm/dd/yyyy'),'690' from dual ;
    insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select      107168 ,'S02',to_date('10/01/2010','mm/dd/yyyy'),'800' from dual; If you want to pick the highest scores, regardless of test date, then don't include test_date in the analytic ORDER BY clause.
    If you want to pick all the rows with the highest score in case of a tie, then use RANK instead of ROW_NUMBER.

  • How I can change this query to group correctly

    This query return the right results for an individual pidm, (SPRIDEN_PIDM = 42306) but not when I run it for all the pidms in the table
    I get something like this which is fine,
    42306
    Z00717850
    2
    42306
    Z00630015
    1
    42306
    Z00822647
    3
    I want to be able to comment it out the   (SPRIDEN_PIDM = 42306) and got the same results for each pidm
    like 
    42306
    Z00717850
    2
    42306
    Z00630015
    1
    42306
    Z00822647
    3
    42807
    Z00717850
    2
    42807
    Z00630015
    1
    42807
    Z00822647
    3
    etc..etc.. it seems that is not grouping correctly
    SELECT
             SPRIDEN_PIDM,
            SPRIDEN_ID,
                ROWNUM
               FROM (SELECT SPRIDEN_PIDM,
             SPRIDEN_ID,
          ROW_NUMBER ()
                   OVER (PARTITION BY sPRIDEN_pidm ORDER BY  SPRIDEN_ID DESC) --- test_date DESC)
                                 rn      
                  FROM (SELECT    SPRIDEN_PIDM,
                                      SPRIDEN_ID
                                      FROM SPRIDEN
                                      WHERE SPRIDEN_ID LIKE 'Z%'
                                     AND SPRIDEN_PIDM = 42306
                                      GROUP BY
                                         SPRIDEN_PIDM ,
                                           SPRIDEN_ID ))
                                  GROUP BY SPRIDEN_pidm,SPRIDEN_ID,ROWNUM
                                  having ROWNUM >= 1

    I think you want to select rn not ROWNUM in the outermost select list - you are generating rn correctly as
    ROW_NUMBER ()
                   OVER (PARTITION BY sPRIDEN_pidm ORDER BY  SPRIDEN_ID DESC)
    but then discarding it.
    i.e.
    SELECT
             SPRIDEN_PIDM,
            SPRIDEN_ID,
                rn
               FROM (SELECT SPRIDEN_PIDM,
             SPRIDEN_ID,
          ROW_NUMBER ()
                   OVER (PARTITION BY sPRIDEN_pidm ORDER BY  SPRIDEN_ID DESC) --- test_date DESC)
                                 rn     
                  FROM (SELECT    SPRIDEN_PIDM,
    To get your results you have too many levels of select - all you need is
    SELECT SPRIDEN_PIDM,
           SPRIDEN_ID,
           ROW_NUMBER ()
                   OVER (PARTITION BY sPRIDEN_pidm ORDER BY  SPRIDEN_ID DESC) --- test_date DESC)
                                 rn     
    FROM   SPRIDEN
    WHERE  SPRIDEN_ID LIKE 'Z%'
      AND  SPRIDEN_PIDM = 42306
    order by SPRIDEN_PIDM,SPRIDEN_ID
    I hope this helps.

  • I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it

    I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it doesnt work

    Hi Timia,
    If you are using Safari as a web browser :-
    Open Safari, go to Safari menu > Preferences > General, and put Google as the homepage. Then, choose Google as your default search engine.
    If you are using Google Chrome as the web browser :-
      Open Google Chrome.
      In the top right corner of the page, click the Chrome menu Chrome menu > Settings.
      In the "Search" section, select Google from the drop-down menu.
    Let me know if you still experience any issue.
    Regards,
    Aadesh

  • I just joined CC and downloaded PS. Since I live in Belgium, it is installed in Dutch, but I would like to get it in English. Anyone knows how I can change this? Thanks!

    HI all,
    I just joined CC and downloaded PS and LR.
    Since I live in Belgium, PS is installed in Dutch, but I would like to get it in English. Anyone knows how I can change this?
    LR is immediately in English so that one is ok.
    Thanks!

    Look at this thread for step by step screenshots on how to do this.
    Photoshop CC / Wrong UI language / How to change? | Adobe Community
    First you add the language, then next you go into Photoshop's Preferences > Interface > UI Language and English should now be an option.
    Change to it and Restart Photoshop

  • My grand daughter has changed the app settings from uk to USA now all the apps are priced in dollars any idea how I can change this back.

    Can anyone help.
    My grand daughter was playing on my iPad. She has some how changed the app for buying apps from uk to the USA. Now all the apps are in dollars and I cannot purchase any because of this.
    Any idea how I can change it back. She can't remember what she did.

    Change App Store
    1. Tap "Settings"
    2. Tap "iTunes & App Stores"
    3. Tap on your Apple ID
    4.Tap "View Apple ID"
    5. Enter your user name and password.
    6. Tap "Country/Region."
    7. Tap "Change Country/Region"
    8. Select the country/region where you are located.
    9. Tap "Done".
    Note: If the change doesn't take effect, sign out of account and sign in again.

  • When i start the browser nationzoom website opens and this startup page is not changing by any procedure given in support website, HOW I CAN CHANGE THIS?

    when i start the browser the Mozilla Firefox' default home page not opens, other website opens nationzoom , i tried all things to change this page to default but it is not changed, following things that i have tried
    1 open options then general then change start page to home page and my home page is default
    2 i read a help topic on Firefox support site there is an add on which removes toolbar i tried this but start up page not changed yet
    please help me about this

    Hello,
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information. <br>
    '''Note''': ''This will cause you to lose any Extensions and some Preferences.''
    *Open websites will not be saved in Firefox versions lower than 25.
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Update ekkn in Z. How I can change this?

    Hi people. I'm changing a Z report and I found this:
          UPDATE ekkn SET ablad = wa_ebkn-ablad
                          wempf = wa_ebkn-wempf
          WHERE ebeln = i_ekkn-ebeln
            AND ebelp = i_ekkn-ebelp
            AND zekkn = i_ekkn-zekkn.
    Anyone knows if exist a BAPI for substitute this update on standard table? Or call transaction?
    Thanks a lot.

    Hi Fulvio,
    Your Update Statement updates values of the ablad and wempf for that particular where condition in that table  ekkn .
    You can  also check in the BAPI  BAPI_PO_CHANGE
    call transaction ME22N
    hope they are useful to you.
    Regards

  • I bought a new ipad, but I cant download purchesed musics cause my id is register to other one. How I can change this?

    How can I reset logs on my IDs, cause I bought other iPad and now is showing that my acount is register to other device and I have to wait xx days to do that?

    Look at this link.
    Giving your former iPad to a spouse or family member: the quick guide
    http://www.tuaw.com/2012/03/17/giving-your-former-ipad-to-a-spouse-or-family-mem ber-the-quick/
    What to do before selling or giving away your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/HT5661
    Find My iPhone Activation Lock: Removing a device from a previous owner’s account
    http://support.apple.com/kb/ts4515
    Buying or Selling a Used iPhone or iPad Running iOS 7? Read This First!
    http://www.makeuseof.com/tag/buying-or-selling-a-used-iphone-running-ios-7-read- this-first/
     Cheers, Tom

  • How I can optimize this SQL query

    I require your help, I want to know how I can optimize this query
    SELECT
                    "F42119". "SDLITM" as "Code1"
                    "F42119". "SDAITM" as "Code2"
                    "F42119". "SDDSC1" as "Product"
                    "F42119". "SDMCU" as "Bodega"
                    Sum ("F42119". "SDSOQS" / 10000) as "Number",
                    Sum ("F42119". "SDUPRC" / 10000) as "preciou"
                    Sum ("F42119". "SDAEXP" / 100) as "Value",
                    Sum ("F42119". "SDUNCS" / 10000) as "CostoU"
                    Sum ("F42119". "SDECST" / 100) as "Cost"
                    "F4101". "IMSRP1" as "Division"
                    "F4101". "IMSRP2" as "classification",
                    "F4101". "IMSRP8" as "Brand"
                    "F4101". "IMSRP9" as "Aroma"
                    "F4101". "IMSRP0" as "Presentation"
                    "F42119". "SDDOC" as "Type",
                    "F42119". "SDDCT" as "Document",
                    "F42119". "SDUOM" as "Unit"
                    "F42119". "SDCRCD" as "currency"
                    "F0101". "ABAN8" as "ABAN8"
                    "F0101". "ABALPH" as "Customer"
                    "F0006". "MCRP22" as "Establishment"
    from          "PRODDTA". "F0101" "F0101"
                    "PRODDTA". "F42119" "F42119"
                    "PRODDTA". "F4101" "F4101"
                    "PRODDTA". "F0006" "F0006"
    where       "F42119". "SDAN8" = "F0101". "ABAN8"
      and         "F0006". "MCMCU" = "F42119". "SDMCU"
      and         "F4101". "IMITM" = "F42119". "SDITM"
      and         "F42119". "SDDCT" in ('RI', 'RM', 'RN')
      and         CAST (EXTRACT (MONTH FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM-                YYYY ') + substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in : Month
    and          CAST (EXTRACT (YEAR FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM-                YYYY ')+ Substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in: Year
    and          trim ("F0006". "MCRP22") =: Establishment
    and          trim ("F4101". "IMSRP1") =: Division
    Group By    "F42119". "SDLITM"
                    "F42119". "SDAITM"
                    "F42119". "SDDSC1"
                    "F4101". "IMSRP1"
                    "F42119". "SDDOC"
                    "F42119". "SDDCT"
                    "F42119". "SDUOM"
                    "F42119". "SDCRCD"
                    "F0101". "ABAN8"
                    "F0101". "ABALPH"
                    "F4101". "IMSRP2"
                    "F4101". "IMSRP8"
                    "F4101". "IMSRP9"
                    "F4101". "IMSRP0"
                    "F42119". "SDMCU"
                    "F0006". "MCRP22"
    I appreciate the help you can give me

    It seems to me that part of fixing it could be how you join the tables.
    Instead of the humongous where clause, put the applicable conditions on the join.
    You have
    from "PRODDTA". "F0101" "F0101"
    "PRODDTA". "F42119" "F42119"
    "PRODDTA". "F4101" "F4101"
    "PRODDTA". "F0006" "F0006"
    where "F42119". "SDAN8" = "F0101". "ABAN8"
    and "F0006". "MCMCU" = "F42119". "SDMCU"
    and "F4101". "IMITM" = "F42119". "SDITM"
    and "F42119". "SDDCT" in ('RI', 'RM', 'RN')
    and CAST (EXTRACT (MONTH FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM- YYYY ') + substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in : Month
    and CAST (EXTRACT (YEAR FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM- YYYY ')+ Substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in: Year
    and trim ("F0006". "MCRP22") =: Establishment
    and trim ("F4101". "IMSRP1") =: Division
    INSTEAD try something like
    from JOIN "PRODDTA". "F0101" "F0101" ON "F42119". "SDAN8" = "F0101". "ABAN8"
    JOIN "PRODDTA". "F42119" "F42119" ON "F0006". "MCMCU" = "F42119". "SDMCU"
    JOIN "PRODDTA". "F4101" "F4101" ON join condition
    JOIN "PRODDTA". "F0006" "F0006" ON join condition.
    Not sure exactly how you need things joined, but above is the basic idea. Remove criteria for joining the tables from the WHERE clause and put them
    in the join statements. That might clean things up and make it more efficient.

  • I want to change my security questions (that I don't remember) but the recovery mail is misspelled wrong by the server (I can't get the email) how I can change done recovery mail without security questions?

    So, yesterday I wanted to buy 2 albums but it was the first buy in this device (I reset mi iPad 2 months ago) so it asked me for my security questions to confirm my identity but since is been a long time since I "used" me security questions I don't remember it so, eventually, I asked for the email to change either my password or my security questions but the email has 2 misspelled letters by a server error instead of being hotmail.com is writted a*******@hormail.clm sop I can't get any email, I already tried changing the mail email and the secondary email but still is the same mail a*******@hormail.clm so how I can change this without my security questions?

    Security questions:
    https://discussions.apple.com/docs/DOC-4551
    http://support.apple.com/kb/HT5312
    This is also useful:
    http://www.macworld.co.uk/ipad-iphone/news/?newsid=3463233&olo=email

  • How can i use my account without the billing info, as i do not have a credit card. and my shipping and billing info is under US. i'm in singapore. how do i change this?

    how can i use my account without the billing info, as i do not have a credit card. and my shipping and billing info is under US. i'm in singapore. how do i change this?

    If you are just visiting Singapore, then leave the account as it is. If you have moved there, then view your account using the iTunes app on a Mac or PC and change the country/region to your current location and address. If you do not have a bank card, you can fund your account using iTunes gift cards if available in Singapore.

Maybe you are looking for

  • Linux - Can't move menu or enable menu bar button (like Windows)

    I have used Firefox 4.0 betas on both Windows and Linux. I notice that unlike Windows, Linux doesn't seem to have the ability to hide the menu under the button which says 'Firefox'. I also cannot move the menu bar and place it on the navigation bar f

  • LC Output - problem big batch of 1000+ records

    Hi, I am creating a prototype with LC Output. The calling application will produce big XML file - Batch with more than1000 records. Example XML data: <?xml version="1.0" encoding="utf-8"?> <BATCH> <formDataRecords> <LC_KOMA002> <customerNameAddress>J

  • Error in Display Fields

    A New issue arised. We have successfully executed an input schedule on our side. Here, the values entered in Display field Areas cannot be send and we get a Popup saying that "There is no data to refresh" But surprisingly, the same input schedule exe

  • Help - canvas doesn't match timeline -- ghost images appear

    Hi, After having no problem in panther and final cut 5.0 I've had to upgrade to tiger (10.4.8) and FCP 5.1.2. When I opened and edited my project, I got a sort of ghost image (a still image from elsewhere in the timeline) appearing in the canvas over

  • How to use FaceTime Between my Mac and my daugher's iPod Touch 4G? It is registered under may Apple ID.

    My daugher has an IpodTouch 4G, registered under my Apple ID since a user must be an adult.  How can we log her in to Facetime?  Any help would be greatly appreciated! I have a brand new MacBook Pro and we'd like to use Facetime when I'm out of town.