How can I 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     Smith
Notice that ruptures in every szstcla_pidm, I need to change the query, so it can display a sequence number 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

Looks like below, this is what you are looking for, but I can't understand why some documents are missing from the sample output

    COL1 COL2     SZSTCLT_LAST_NAME              RN
-------- -------- ------------------------------ --

  120125 200920   Smith                           1
  120125 201010   Smith                           2 

Maybe, if you could explain it, the query can be modified to exclude these folders as well. But, for now, downwards should suffice.

select szstclt_pidm col1, szstclt_term_code col2, szstclt_last_name, row_number() over (partition by szstclt_pidm order by szstclt_term_code) rn
  from szstclt a
       join shrtgpt b on a.SZSTCLT_PIDM = b.SHRTGPT_PIDM and a.SZSTCLT_TERM_CODE = b.SHRTGPT_TERM_CODE
 where SZSTCLT_PIDM IN ( 120125,186114);

    COL1 COL2     SZSTCLT_LAST_NAME              RN
-------- -------- ------------------------------ --
  120125 200920   Smith                           1
  120125 201010   Smith                           2
  120125 201020   Smith                           3
  120125 201110   Smith                           4
  120125 201120   Smith                           5
  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 

 13 rows selected 

Tags: Database

Similar Questions

  • How can I 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_CODE
    Returns
    74246     201020     4
    74246     201120     4
    74246     201110     4
    74246     201210     4
    74246     201220     4
    I want to group the query will return
    74246 201020     4
    74246 201120     8
    74246 201110     12
    74246 201210     16
    201220 20

    Two copies

    Published by: Frank Kulash, November 8, 2012 11:32

  • I changed my email address but my weekly activity reports are sent to my old email address always, how can I change this?

    I changed my email address but my weekly activity reports are sent to my old email address always, how can I change this?

    All my account settings read my new email address, but in the security settings for the family where it shows you where your children's accounts are linked to its display of my old email address but I am unable to change it.  Is could someone please tell me how to update the email address?

    Hi Rachel,

    Thanks for posting your query in Microsoft Community.

    I suggest you to check out the article below and check if it helps.

    Change the address where should be sent the reports of parental control

    Please get back to us if you need further assistance.

  • Sage (simply accounting) the icon is still adobe but I can get in. How can I change this

    I did a restore of my backup cd. The icons are still adobe. I can't get into the programs when I click on the icon. If not, how can I change this back to what they were?

    Thank you

    [Moved from the forum comments]

    Hi Marlayne,

    Thanks for posting your query on the Microsoft Community.

    Could you please answer the following questions so that I can help you best.

    1. what operating system do you use?

    You can check this link for the operating system.

    http://Windows.Microsoft.com/en-us/Windows/which-operating-system

    2 are. what icons you referring?
    3. what programs you're talking about?
    4. What happen exactly when you click the icon?
    5. you receive an error message when you try to open the programs?

    I suggest you to try the fixit from the link below.

    Diagnose and repair Windows files and folders problems automatically
    http://support.Microsoft.com/mats/windows_file_and_folder_diag/

    Hope the above information helps.

    Do get back to us and let us know the State of the issue of your next post or in the cases where you need assistance about Windows.

  • Windows 7 network connection status sent/received packets in bytes by default. How can I change this setting so that the status is displayed in MBs.

    Windows 7 network connection status sent/received packets in bytes by default. How can I change this setting so that the status is displayed in MBs.

    Hey Muhammad,

    Thanks for posting the query on Microsoft Community.

    Design/default it appears in bytes not in MB.

    In the future, if you have problems with Windows, get back to us. We will be happy to help you.

  • How can I change this request, so I can display the name and partitions in a r

    How can I change this request, so I can add the ID of the table SPRIDEN
    from now on gives me what I want:
     
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20
    in a single line, but I would like to add the id and the name that is stored in the SPRIDEN table

     
    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;
                    

    Hello

    That depends on whether spriden_pidm is unique, and you want to get the results.

    Whenever you have a problem, post a small example of data (CREATE TABLE and INSERT, relevamnt columns only instructions) for all the tables and the results desired from these data.
    If you can illustrate your problem using tables commonly available (such as in the diagrams of scott or HR) so you need not display the sample data; right after the results you want.
    Whatever it is, explain how you get these results from these data.
    Always tell what version of Oracle you are using.

    Looks like you are doing something similar to the following.
    Using the tables emp and dept of the scott schema, producing a line of production by Department showing the highest salary for each job, for a set given 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     950
    

    On each line, jobs are listed in order by the highest salary.
    This seems to be similar to what you are doing. The roles played by the sortest_pidm, sortest_tesc_code and sortest_test_score in your table sortest are played by deptno, job and sal in the emp table. The roles played by the spriden_pidm, id and the name of your table spriden are played by deptno, dname and loc in the dept table.

    Looks like you already have something like the query below, which produces a correct output, except that it does not include the dname and loc of the dept table columns.

    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
    ;
    

    Dept.DeptNo is unique, it won't be a dname and a loc for each deptno, so we can modify 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
    ;
    

    In fact, you can continue to use just deptno in the analytical PARTITION BY clause. It may be slightly more efficient to just use deptno, as I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc by deptno.

    Moreover, you don't need so many subqueries. You use the internal subquery to calculate the MAX and the outer subquery to calculate rn. Analytical functions are calculated after global fucntions so you can do both in the same auxiliary request 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
    ;
    

    It will work in Oracle 8.1 or more. In Oracle 11, however, it is better to use the SELECT... Function PIVOT.

  • When I download a file, there is a very strong sound Horn when it ends. How can I change this noise?

    When I download a video or a file, the alert when you have finished its is very strong and unpleasant. How can I change this alert?

    I find the problem in an add-on as suggested you do that of the add-on sound came and stopped. Thanks for all the help.

    I tried to mark it as resolved, but said access denied oh well.

  • Firefox always opens at 120%. How can I change this permanently?

    When I open Firefox, the zoom is still at 120%. How can I change this permanently?

    Hi, try to change the zoom level (Ctrl and + key, or Ctrl and - key). - The font size and zoom - increase the size of the web pages.

    Note: It is possible that your NoSquint extension is changing the default operation, if so, either turn it off, or look at settings - modules Manager Ctrl + Shift + A.

    If your question is resolved by this or another answer, please take a minute to let us know. Thank you.

  • I have a few Web sites that load in mobile in Firefox. How can I change this?

    I have a few Web sites that only the moving load on my desk for computer laptop-widows 8.1. How can I change this?

    What are the dimensions of the browser window?
    Some website changes automatically the movable display if you make the window too small.

    Can you attach a screenshot and possibly post some links?

    • Use a type of compressed as PNG or JPG image to save the screenshot
    • Make sure you do not exceed the maximum size of 1 MB

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem.

    • Put yourself in the DEFAULT theme: Firefox/tools > Modules > appearance
    • Do NOT click on the reset button on the startup window Mode safe
  • My iPhone 5 and Mac Office e-mail accounts are linked, so when I delete emails from my phone, they are also deleted from my Mac.  How can I change this?

    When I delete emails from my iPhone 5, same emails deleted from my Mac desktop.  There are a lot of emails that I want to keep on my desk that I don't want to keep on my phone, for reasons of capacity and convenience.  This link happened recently - before that, I could remove the phone without deleting the computer.  How can I change this?

    This looks like what an IMAP email account made by design. This isn't a matter of Apple.

    Is what email provider? How do you account set up?

    Get help if you have any questions using a POP email with multiple devices - Apple Support account

  • Devices on all my iCloud preferences says "this device can be used to receive codes of audit ID Apple." How can I change this if at least one, if not several, can receive the verification code?

    Devices on all my iCloud preferences says "this device can be used to receive codes of audit ID Apple." How can I change this if at least one, if not several, can receive the verification code?

    Try to go here and see if you can add them to your Apple ID.

  • Where Thunderbird stores my e-mail in Windows 7 and how can I change this somewhere else?

    I want to assure you that I am saving my e-mail messages, so I need to know where is stored mail messages (not the profile). If it is stored on the C: drive where are all of my programs, I will probably want to change to a data reader as I backup on a regular basis. How can I change this location and move my existing files there? Thank you

    https://support.Mozilla.org/en-us/KB/Profiles-TB#w_moving-a-profile

    Note that profiles.ini must stay where it is and you move everything else. Thunderbird must be able to find and open up profiles.ini to locate the rest.

    However, if you use a reader for programs (perhaps a SSD?) and hard drives for all your data, it would be preferable to find the setting in windows to move all your users on the HARD drive folders. Then the link magic used by Windows token % appdata % will point to the correct location.

  • All of a sudden started having a large margin on both sides of websites such as Facebook and Pinterest so everything is smaller in the middle. How can I change this?

    I don't know if I've accidentally changed something by mistake, but now most of the Web pages on which I'm going to have a margin of 2 inches on both sides which makes everything that should appear in a small space right in the middle of the screen. I would like to make the content of the pages to fill the entire page rather than just middle. How can I change this?

    You can reset the zoom of page on pages that are causing problems.

    • View > Zoom > reset (Ctrl + 0 (zero); 0 + Command on Mac)
  • The new tab behavior is driving me crazy. It keeps re-centering on legs closest to the top of the list when I move a tab. How can I change this?

    The new tab behavior is driving me crazy. It keeps re-centering on legs closest to the top of the list when I move a tab. How can I change this?

    I don't want to download an application. I would rather add a new string in any config or just change those there to false. It makes my life as a rather hard work, to be forced to go all the way back at the end of my list after you move a tab just to have to do it again. I mean it's to the point where I could consider changing browsers if they had tab scrollbars.

    Edit: Now I will download any application. Please stop this stupid feature.

    I downloaded the beta version and it stopped. Thank you all for trying to help anyway. I probably didn't explain my problem very well in the first place, but you tried to help him. Thank you.

  • The changed graphic line in the histogram chart on my health application. How can I change this back?

    The graphic on my health application under a line chart to a bar chart.  How can I change this back?

    Answer is simple: you can not change it back because of the update of IOS.

    BUT why have they changed it? Us users want to line charts!

    Anyone care to explain Apple? This is quite annoying...

Maybe you are looking for

  • Portege R200: Need keycodes for the mapping of the keys

    Hello There are many great mapping software keycodes GNU/Linux (like the quick access keys or fnfxd) but we need keycodes to use.I would like to know what are the codes that are bound to (1) TOSHIBA Assist buttonPresentation button 2) TOSHIBA for the

  • All-in-one Officejet 5610: function Scan lost after upgrade to Yosemite

    Lost the ability to analyze after upgrade, print, and copy works. Have already done everything suggested by Double-U-di in the Mac OS 10.10 post Yosemite and HP Printer Support posted on 30/10/2014: checking for updates Apple, printer removed from th

  • Download a digital copy of the golden age of empires 2

    I just happen to have broken or lost my age of empires 2 gold edition CD. but still the cd key. I was wondering if there was a way to register online in order to download a digital customer because my cd is gone. or I could get a new one. but I alway

  • printer large format

    We recently purchased a printer large format, the Z6600 and it came with a Cyan ink cartridge. I'm having a hard time finding a replacement of the cyan cartridge. I don't see Light Cyan for the purchase of supplies.

  • What is the best way in grayscale, an image that has a lot of dark colors?

    I try to calm black and darker colors so that they are all shades of gray for a book coloring grayscale. Some pictures when I use various means of grayscaling, the darker colors are still too dark. Especially in the lower left Tulip. If I try the dod