get the value of the maximum value of a column for a particular type

Hello.
I have a query which returns the output something like

Type of VersionNo ID ProductID VersionID category unusual
1130 16650 16650 1193 5 Category1
1130 16650 16650 1205 5 Category2
1130 16650 16650 1242 5 category3
1130 16650 1130 1001 1 Category1
1130 16650 1130 1081 1 category3
1131 16656 16656 1193 4 Category1
1131 16656 16656 1205 4 Category2
1131 16656 16656 1240 4 category3
1131 16656 1131 1001 1 Category1
1131 16656 1131 1081 1 category3

I want to see the result that all the VersionId for the same ID values should have the same value for the category and it should be the value that is there for the maximum versionNo for a particular Type of «» Something like


Type of VersionNo ID ProductID VersionID category unusual
1130 16650 16650 1193 5 Category1
1130 16650 16650 1205 5 Category2
1130 16650 16650 1242 5 category3
1130 16650 1130 1193 1 Category1
1130 16650 16650 1205 1 Category2
1130 16650 1130 1242 1 category3
1131 16656 16656 1193 4 Category1
1131 16656 16656 1205 4 Category2
1131 16656 16656 1240 4 category3
1131 16656 1131 1193 1 Category1
1131 16656 16656 1205 1 Category2
1131 16656 1131 1240 1 category3

Does anyone know how to do this?

Ok
Try:

WITH test_data AS (
SELECT 1130 RecID, 16650 ProductID,  16650 VersionID, 1193  Category,  5 VersionNo, 'Category1' Type FROM DUAL UNION ALL
SELECT 1130, 16650, 16650, 1205, 5, 'Category2' FROM DUAL UNION ALL
SELECT 1130, 16650, 16650, 1242, 5, 'Category3' FROM DUAL UNION ALL
SELECT 1130, 16650, 1130, 1193, 1, 'Category1' FROM DUAL UNION ALL
SELECT 1130, 16650, 1130, 1205, 1, 'Category2' FROM DUAL UNION ALL
SELECT 1130, 16650, 1130, 1242, 1, 'Category3' FROM DUAL),
-- end test data
max_data AS (
SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
  FROM test_data td1
 WHERE VersionNo = (
  SELECT MAX(VersionNo)
    FROM test_data td2
  WHERE td1.RecID = td2.RecID
     AND td1.ProductId = td2.ProductID))
SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
  FROM max_data
  UNION
SELECT md1.RecID, md1.ProductID, td1.VersionID, md1.Category, td1.VersionNO, md1.Type
  FROM max_data md1
  JOIN test_data td1
 ON (md1.RecID = td1.RecID AND md1.ProductID = td1.ProductID)
ORDER BY 1,2,3,5, 6

     RECID  PRODUCTID  VERSIONID   CATEGORY  VERSIONNO TYPE
---------- ---------- ---------- ---------- ---------- ---------
      1130      16650       1130       1193          1 Category1
      1130      16650       1130       1205          1 Category2
      1130      16650       1130       1242          1 Category3
      1130      16650      16650       1193          5 Category1
      1130      16650      16650       1205          5 Category2
      1130      16650      16650       1242          5 Category3

And you simply:

WITH max_data AS (
SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
  FROM test_data td1
 WHERE VersionNo = (
  SELECT MAX(VersionNo)
    FROM test_data td2
  WHERE td1.RecID = td2.RecID
     AND td1.ProductId = td2.ProductID))
SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
  FROM max_data
  UNION
SELECT md1.RecID, md1.ProductID, td1.VersionID, md1.Category, td1.VersionNO, md1.Type
  FROM max_data md1
  JOIN test_data td1
 ON (md1.RecID = td1.RecID AND md1.ProductID = td1.ProductID)
ORDER BY 1,2,3,5, 6

Tags: Database

Similar Questions

  • Get the maximum index of a vector of growth

    Hello

    I'm having a very strange problem. I simulate data with an sine function in a while loop and I keep the values< 0.7="" into="" a="" vector.="" when="" the="" sinus="" values="" are="" over="" 0.7,="" i="" remove="" the="" vector.="">

    I would like to get the maximum index of the vector at each iteration of the loop. However, I get a zero index while the vector has a size > 0.

    It's really strange, because if I put the values of the iteration instead of the values of the sine, the index created is correct (the only difference is that the iteration number is an integer, while the sine is a decimal number).

    To make someone understand something?

    Thanks for your help

    Andrew

    Instead of "delete table", just leave the REAL empty case and 'use default if unwired' on the output of the table tunnel.

    Once the sinuses is once again<0.7, you="" are="" on="" the="" descending="" branch,="" so="" the="" first="" element="" is="" always="" the="" largest="" for="" a="" while.="" nothing="" wrong="" with="">

    I would also put indicators after the case structure so they update in all conditions.

    Table min & Max will give you the index of the element with the highest value. If you want to know the size of the array, use the function "size of array".

  • How to get the maximum number of iterations in the property of TS

    I was put the loopType from one step to the count of success/failure. For example "stop after 1 iterations pass or a maximum of 3 iterations. The maximum iteration is 3. What my qustion is how to get the maximum iteration of TS property by codes of trial during the race. Thank you very much!

    Corey Chen

    The OPPO test developer

    Hello

    It may be a hack, but RunState.Step.LoopWhileExpression has information.  It will return a string like: "RunState.LoopIndex."< 69="" &&="" runstate.loopnumpassed=""><>

  • How to get the maximum number of days in a month?

    How to get the maximum number of days in a month?

    I use a dateField. where I can get the month. Now, I want to get the maximum number of days in a month.

    How can I get it?

    Please help me. and thanks in advance... []

    NET. RIM. Device.API.util
    Class DateTimeUtilities

    getNumberOfDaysInMonth (int month, int year)
    Returns the number of days in the specified month

    It took me like 10 seconds to find it in the API, I guess you spent more time writing the post...

  • Unable to get the maximum screen resolution when you use the external monitor

    Hello

    I use Windows 8 on laptop ASUS K55A. I use an external monitor (Samsung SyncMaster 2233BW). Everything works fine except that I do not get the maximum resolution on the external display. The only way I see a sort of an overview of the good resolution is when I choose "extend these screens", but it's very uncomfortable when there's always one screen, I don't actually see.
    How can I increase the resolution of the screen on the external screen? (now, it's on 'show desktop only on 2')
    Thank you!
    I use Windows 8 on laptop ASUS K55A.

    So first a Bing search finds that ASUS K55A probably has the chip Intel HD 4000

    Then,

    https://communities.Intel.com/thread/30360

    (BING search engine for)
    Two monitors specifications Intel HD Graphics 4000

    )

    Graphics card Intel doesn't support double bond, so 1920 x 1200 is the maximum for DVI and HDMI, 2560 x 1440 is only possible with a display port. This is indicated in each product page.

  • How can I get the maximum salary of the first ascending

    Hello

    How can I get the maximum salary of the first in ascending order.
    I need the sql query.

    want my output:

    Emp_name salary
    A 5000
    SS 100
    300 AA
    DD 700
    WW 2000



    Thank you
    Walid.

    Here is an example:

    SQL> with mytable as
      2  ( select 'aa' as col1,  300 col2 from dual union all
      3    select 'ss' as col1,  100 col2 from dual union all
      4    select 'a'  as col1, 5000 col2 from dual union all
      5    select 'dd' as col1,  700 col2 from dual union all
      6    select 'ww' as col1, 2000 col2 from dual )
      7  select col1, col2
      8  from   mytable
      9  order by decode(row_number() over (order by col2 desc),1,0,1),col2;
    
    CO       COL2
    -- ----------
    a        5000
    ss        100
    aa        300
    dd        700
    ww       2000
    
    SQL>
    

    Nicolas.

  • I get the following error during synchronization itunes for itouch - 0xE800400C

    I get the following error during synchronization itunes for itouch - 0xE800400C.
    Takes forever to sync music and then fails with the above error and also says "device timed out"?
    Please, please help...
    Mar.x

    Hello

    ·        What is the version of iTunes installed on your computer?

    ·        This device was working fine before?

    ·        Is there any software or hardware changes made to the computer, after which, the problem occurred?

    Try uninstalling and reinstalling iTunes and check if that helps. To uninstall the application follow the link below.

    Uninstall or change a program

    http://Windows.Microsoft.com/en-us/Windows7/uninstall-or-change-a-program

    Download and reinstall the latest version of iTunes. Follow the link given below, get iTunes now.

    www.Apple.com/itunes/download/.

    You can also contact Apple support for further assistance.

    http://www.Apple.com/support/

    Hope this information is useful.

    Amrita M

    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How to get the last date of 3 days for the current month?

    Hello. Guy

    How to get the last date of 3 days for the current month?

    MY OUTPUT WOULD LOOK LIKE THIS

    JANUARY 29, 2016

    JANUARY 30, 2016

    JANUARY 31, 2016


    GUYS HELP ME / / /...

    SQL > select last_day (sysdate) - level + 1 double connect by level<= 3="" order="" by="">

    LAST_DAY)

    ---------

    29 JANUARY 16

    30 JANUARY 16

    31 JANUARY 16

  • Recently purchased captivate subscription 9 and installed on mac. When I try to open I get the message ' to open Adobe Captivate for must install legacy Java SE 6 runtime. " I followed the links and recommended all intalled the update of Java. How the % $

    Recently purchased captivate subscription 9 and installed on mac. When I try to open I get the message ' to open Adobe Captivate for must install legacy Java SE 6 runtime. " I followed the links and installed all updates Java recommended. How the % $# & not one open and use 9 Captivate? Any suggestions?

    Hello

    This link may help: easy to install Java SE 6 Runtime | Mac OS 10.9

    Kind regards

    Sheena

  • Hi, I need to download the acrobat PDF after registration and cc payment, I get the new which is not available for mac ist... How can I solve this problem... I use only the mac...

    Hi, I need to download the acrobat PDF after registration and cc payment, I get the new which is not available for mac ist... How can I solve this problem... I use only the mac...

    If you had bought subscription Acrobat Standard / stand-alone product , you need to cancel the subscription / order and re - register / re - order subscription Acrobat Pro DC / stand-alone product.

  • Hi, well, I want to get the creative cloud cuz I need for my career as urgent, but I will change my phone soon, so my question is... can I install in my pc, and then move them to another without paying again or something?

    Hi, well, I want to get the creative cloud cuz I need for my career as urgent, but I will change my phone soon, so my question is... can I install in my pc, and then move them to another without paying again or something?

    Yes.

    You can install an unlimited number of computers.  You can connect to up to two computers at any time (and you must be connected to use your cc programs).

    It's quick and easy to sign in and out, so there is no downside on the use of the cc on different computers.  legally, only the licensee is authorized to use the subscription of the cc if you can't share your programs with another person, but this is the only restriction.

    you have just installed you are the application of cc desktop on any computer you use, Download Adobe Creative Cloud apps | CC free trial Adobe

    Connect, connect and disconnect activate Cloud Creative applications

    Use the desktop application to install your programs of cc.

  • Determine the maximum length of a column and its use in the same query?

    I would like to determine the maximum length of a column and use it in the same query. Is this possible? IE:

    SELECT RPAD (last_name, SELECT MAX (LENGTH (last_name)) + 5 FROM user, '-')
    OF the user.

    Thank you

    Hello

    Welcome to the forum!

    jfraley wrote:
    I would like to determine the maximum length of a column and use it in the same query. Is this possible? IE:

    SELECT RPAD (last_name, SELECT MAX (LENGTH (last_name)) + 5 FROM user, '-')
    OF the user.

    Thank you

    Sure. You almost go in your message: a scalar subquery . Just put brackets around the subquery:

    SELECT      RPAD ( last_name
              , (
                 SELECT  MAX (LENGTH (last_name)) + 5
                 FROM    user_tbl          -- USER is not a good table name
                )
              , '-'
              )          AS padded_last_name
    FROM      user_tbl
    ;
    

    Scalar subqueries in SQL are like tape in your garage in canvas: they are used for thousands of different things and open, maybe 1% of them. Usually, there are better ways to achieve the same results, such as the analytical functions:

    SELECT      RPAD ( last_name
              , 5 + MAX (LENGTH (last_name)) OVER ()
              , '-'
              )          AS padded_last_name
    FROM      user_tbl
    ;
    

    Still another way is to make the subquery and then join his game as if it were a table of results:

    WITH     got_max_length     AS
    (
         SELECT     MAX (LENGTH (last_name))     AS max_length
         FROM     user_tbl
    )
    SELECT      RPAD ( u.last_name
              , m.max_length + 5
              , '-'
              )          AS padded_last_name
    FROM           user_tbl     u
    CROSS JOIN     got_max_length     m
    ;
    

    Published by: Frank Kulash, December 12, 2011 21:17
    Added cross join example

  • Persistent for the subtraction of the background image collection (how to get the maximum value of each pixel in a series of images IMAQ)

    Hi all

    I have a system of LabVIEW which takes advantage IMAQ tools and features of the Vision Development Module.  A useful feature that I put in place is to be able to take a snapshot of the video stream and then subtract this single image among the subsequent images.

    What I want to do is to collect a series of images instead of one, and then create a unique image of these frameworks is just the maximum value of pixels in each pixel (a bit like a display persistent).

    It would probably be very easy to be implemented by converting the image to a table and then by doing math number on the table and then turning into an image, but I hope that someone here may know how to use the IMAQ/VDM tools to do this in a way more compact.

    Thank you very much

    MK

    How about using Max comparison IMAQ operation?

  • query to get the maximum integer value of varchar columns

    I have the following values in the column of type Varchar.

    USR_LOGIN (VARCHAR2)
    -----------------------------
    50
    52
    53
    55
    57
    123
    111
    145
    XELSYSADM
    TESTUSER
    USER123
    12TESTUSER

    But I need to get the result as 145.

    Can you help me with the sql query?

    Maybe it's

    SQL> with t as (
     select '50' usr_login from dual union all
     select '52' from dual union all
     select '53' from dual union all
     select '55' from dual union all
     select '57' from dual union all
     select '123' from dual union all
     select '111' from dual union all
     select '145' from dual union all
     select 'XELSYSADM' from dual union all
     select 'TESTUSER' from dual union all
     select 'USER123' from dual union all
     select '12TESTUSER' from dual
    )
    --
    --
    select max(to_number(regexp_substr(usr_login, '\d+'))) usr_login from t
    /
          USR_LOGIN
    ---------------
                145
    1 row selected.
    
  • SQL: How to get the maximum value of loans

    I have to display cod_acct_no, amt_disbursed, bal_book in table LOAN_MAST and maximum version of table LOAN_SCHEDULE CTR_STAGE_NO amt_instal. in other words; amt_instal of the most ctr_stage_no of table LOAN_SCHEDULE to display with the other value of LOAN_MAST column.

    You could help me pls.

    Data from these two tables are provided below:

    Main table ready
    INSERT INTO loan_mast
    VALUES
    ('00057110000431  ',2000000,1010605.39)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057110000291  ',3500000,1212038.57)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057110000450  ',2000000,1179199.79)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057010001457  ',2000000,1555836.32)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057010001650  ',9500000,8060419.1)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057110050065  ',2000000,1742388.45)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057010001947  ',2000000,1933540.07)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057110050213  ',2000000,1978588.06)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037010001104  ',6175000,3241694.48)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037010001766  ',12000000,11715781.01)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037300050025  ',7500000,7472981.78)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037210000694  ',6500000,6588648.16)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000087  ',5000000,4105246.38)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000129  ',5000000,3478303.49)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000141  ',5000000,3685293.79)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000246  ',5000000,4029883.61)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000268  ',5000000,4499322.1)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000322  ',5000000,4966885.32)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017300050014  ',7000000,6625970.85)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017300050036  ',5700000,5687617.61)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017300050047  ',7500000,7527560)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017240000050  ',4300000,4300000)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017210000449  ',7000000,7000000)
    /
    INSERT INTO loan_mast
    VALUES
    ('03017180001733  ',500000,335164.83)
    /
    INSERT INTO loan_mast
    VALUES
    ('01117110050071  ',700000,625123.9)
    /
    INSERT INTO loan_mast
    VALUES
    ('01077300050011  ',1500000,1447149.08)
    /
    INSERT INTO loan_mast
    VALUES
    ('00927180002119  ',500000,441488.25)
    /
    INSERT INTO loan_mast
    VALUES
    ('01507150051043  ',700000,633340.47)
    /
    INSERT INTO loan_mast
    VALUES
    ('03317290050040  ',300000,273601.45)
    /
    INSERT INTO loan_mast
    VALUES
    ('01027150051360  ',200000,179240.42)
    /
    INSERT INTO loan_mast
    VALUES
    ('01067150052782  ',300000,270794.1)
    /
    INSERT INTO loan_mast
    VALUES
    ('01137110050082  ',2000000,1786359.87)
    /
    INSERT INTO loan_mast
    VALUES
    ('01107150050610  ',200000,191399.56)
    /
    INSERT INTO loan_mast
    VALUES
    ('01117150051071  ',300000,271560.17)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001052  ',6800000,6609837.58)
    /
    INSERT INTO loan_mast
    VALUES
    ('01157010001078  ',450000,425069.61)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017180001173  ',700000,484447.94)
    /
    INSERT INTO loan_mast
    VALUES
    ('09997120004696  ',93099,64369.52)
    /
    INSERT INTO loan_mast
    VALUES
    ('01067010001654  ',285000,255579.7)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001063  ',7000000,6930746)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001105  ',7000000,6934246)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001138  ',7000000,7000000)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001116  ',7000000,7000000)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001161  ',7000000,7000000)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001150  ',7000000,7000000)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210001127  ',7000000,6930746)
    /
    INSERT INTO loan_mast
    VALUES
    ('00067110050043  ',700000,602416.77)
    /
    INSERT INTO loan_mast
    VALUES
    ('01147150052362  ',200000,178682.78)
    /
    INSERT INTO loan_mast
    VALUES
    ('01167150051647  ',75000,60057.01)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017150053252  ',150000,125205.66)
    /
    INSERT INTO loan_mast
    VALUES
    ('00917150050232  ',100000,91972.04)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017180003081  ',990000,663015.26)
    /
    INSERT INTO loan_mast
    VALUES
    ('09997220000893  ',154160,138665.08)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017210000955  ',5000000,4510523.32)
    /
    INSERT INTO loan_mast
    VALUES
    ('00087150001049  ',1000000,904601.41)
    /
    INSERT INTO loan_mast
    VALUES
    ('01107010000288  ',300000,268703.55)
    /
    INSERT INTO loan_mast
    VALUES
    ('00087150001038  ',1000000,906085.9)
    /
    INSERT INTO loan_mast
    VALUES
    ('01107010000277  ',200000,184905.75)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017080050030  ',500000,450047.42)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037210000533  ',4000000,3346908.17)
    /
    INSERT INTO loan_mast
    VALUES
    ('01117180000631  ',990000,712874.67)
    /
    INSERT INTO loan_mast
    VALUES
    ('02007180001216  ',990000,792437.11)
    /
    INSERT INTO loan_mast
    VALUES
    ('01957180000928  ',400000,320317.9)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037210000544  ',600000,518404.4)
    /
    INSERT INTO loan_mast
    VALUES
    ('01117110050060  ',1000000,893034.07)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037180001877  ',800000,640405)
    /
    INSERT INTO loan_mast
    VALUES
    ('01047150052651  ',320000,288850.72)
    /
    INSERT INTO loan_mast
    VALUES
    ('01027160050103  ',100000,79915.86)
    /
    INSERT INTO loan_mast
    VALUES
    ('01067150052759  ',150000,129601.15)
    /
    INSERT INTO loan_mast
    VALUES
    ('01057150051287  ',800000,723681.12)
    /
    INSERT INTO loan_mast
    VALUES
    ('03317290050021  ',400000,359312.25)
    /
    INSERT INTO loan_mast
    VALUES
    ('01157150051316  ',500000,452300.73)
    /
    INSERT INTO loan_mast
    VALUES
    ('00037150050598  ',700000,633221.03)
    /
    INSERT INTO loan_mast
    VALUES
    ('01047150052673  ',150000,129610.95)
    /
    INSERT INTO loan_mast
    VALUES
    ('01147150052384  ',400000,361840.54)
    /
    INSERT INTO loan_mast
    VALUES
    ('01067150052802  ',150000,130840.94)
    /
    INSERT INTO loan_mast
    VALUES
    ('01157150051338  ',300000,259202.22)
    /
    INSERT INTO loan_mast
    VALUES
    ('01057150051307  ',400000,361840.54)
    /
    INSERT INTO loan_mast
    VALUES
    ('00017110050160  ',500000,397640.38)
    /
    INSERT INTO loan_mast
    VALUES
    ('01077150050910  ',100000,79915.86)
    /
    INSERT INTO loan_mast
    VALUES
    ('00057150050702  ',400000,360841.83)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017150053271  ',150000,119955.86)
    /
    INSERT INTO loan_mast
    VALUES
    ('01057150051329  ',400000,360029.85)
    /
    INSERT INTO loan_mast
    VALUES
    ('01067150002665  ',500000,452300.73)
    /
    INSERT INTO loan_mast
    VALUES
    ('01077150050921  ',250000,225526.17)
    /
    INSERT INTO loan_mast
    VALUES
    ('00047150050693  ',200000,160494.64)
    /
    INSERT INTO loan_mast
    VALUES
    ('01077080050026  ',100000,91150.55)
    /
    INSERT INTO loan_mast
    VALUES
    ('01017150053293  ',150000,129675.2)
    /
    INSERT INTO loan_mast
    VALUES
    ('09997040001950  ',2500000,2439161.01)
    /
    INSERT INTO loan_mast
    VALUES
    ('09997120004685  ',75000,51855.74)
    /
    Table of loan from schedule+:
    INSERT INTO loan_schedule
    VALUES
    ('00017080050030  ',1,12426.29)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00017110050160  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00017110050160  ',2,17702.2)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00017180001173  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00017180001173  ',2,35116.22)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037150050598  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037150050598  ',2,18158.39)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037180001877  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037180001877  ',2,29122.98)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037210000533  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037210000533  ',2,144609.59)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037210000544  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00037210000544  ',2,17625)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00047150050693  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00047150050693  ',2,7331.21)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00057150050702  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00057150050702  ',2,10157.38)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00067110050043  ',1,20017.91)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00087150001038  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00087150001038  ',2,25940.56)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00087150001049  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00087150001049  ',2,25940.56)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00917150050232  ',1,2937.5)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00927180002119  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('00927180002119  ',2,25083.02)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017150053252  ',1,5422.86)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017150053271  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017150053271  ',2,5422.86)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017150053293  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017150053293  ',2,4406.25)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017180003081  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017180003081  ',2,49664.37)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017210000955  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01017210000955  ',2,126967.14)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01027150051360  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01027150051360  ',2,5980.03)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01027160050103  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01027160050103  ',2,3615.24)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01047150052651  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01047150052651  ',2,8125.9)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01047150052673  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01047150052673  ',2,4406.25)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051287  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051287  ',2,20752.45)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051307  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051307  ',2,10376.23)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051329  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01057150051329  ',2,11960.05)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067010001654  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067010001654  ',2,6855.16)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150002665  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150002665  ',2,12970.28)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052759  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052759  ',2,4406.25)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052782  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052782  ',2,7618.03)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052802  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01067150052802  ',2,5422.86)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077080050026  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077080050026  ',2,2485.26)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077150050910  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077150050910  ',2,3615.24)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077150050921  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077150050921  ',2,6348.36)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077300050011  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01077300050011  ',2,23289.97)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01107010000277  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01107010000277  ',2,4550.62)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01107010000288  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01107010000288  ',2,7215.96)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01107150050610  ',1,5188.12)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117110050060  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117110050060  ',2,23528.29)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117110050071  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117110050071  ',2,16469.8)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117150051071  ',1,7782.17)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117180000631  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01117180000631  ',2,49664.37)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01137110050082  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01137110050082  ',2,47056.57)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01147150052362  ',1,5875)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01147150052384  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01147150052384  ',2,10376.23)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157010001078  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157010001078  ',2,10764.62)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157150051316  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157150051316  ',2,12970.28)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157150051338  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01157150051338  ',2,8812.5)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01167150051647  ',1,2711.43)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01507150051043  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01507150051043  ',2,18158.39)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01957180000928  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('01957180000928  ',2,14561.49)
    /
    INSERT INTO loan_schedule
    VALUES
    ('02007180001216  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('02007180001216  ',2,36039.68)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03017180001733  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03017180001733  ',2,25083.02)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03317290050021  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03317290050021  ',2,9833.81)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03317290050040  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('03317290050040  ',2,7375.36)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997040001950  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997040001950  ',2,13864.94)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997120004685  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997120004685  ',2,3495.59)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997120004696  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997120004696  ',2,4339.15)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997220000893  ',1,0)
    /
    INSERT INTO loan_schedule
    VALUES
    ('09997220000893  ',2,3429.21)
    /
    Kind regards

    Yamen

    Hello

    When there is a WHERE clause, it always comes after the FROM clause. (Joints and their conditions are part of the FROM clause).
    Try this:

    WITH     got_rnum    AS
    (
         SELECT     cod_acct_no
         ,     amt_instal
         ,     ROW_NUMBER () OVER ( PARTITION BY  cod_acct_no
                                   ORDER BY          ctr_stage_no       DESC
                           ) AS rnum
         FROM    loan_schedule
    )
    SELECT     m.cod_acct_no, m.amt_disbursed, m.bal_book
    ,     r.amt_instal             AS high_amt_instal
    FROM     loan_mast     m
    JOIN     got_rnum     r     ON     r.cod_acct_no     = m.cod_acct_no
                        AND     r.rnum          = 1
    WHERE   m.cod_acct_stat = '8' ----------[this is condition is newly added to apply the same in production to fetch desired record]
    ;
    

Maybe you are looking for