Avatar of Farzad Akbarnejad
Farzad AkbarnejadFlag for Iran, Islamic Republic of

asked on 

Last Function in Group By Query in Oracle

Hello,

I have a table with the following data:


            RWSHID            RISUID       JOBCODE
  ---------------------------------------------------------
      0188280314      0010202751      000000
      0188280314      0010202751      024019
      0188280314      0010202751      024043
      0188280314      0010424521      000000
      0188280314      0010424521      024043
      0188280314      0010424521      027212
      0188280314      0010454707      007005
      0188280314      0010454707      024019
      0188280314      0010454707      024043
      0188280314      0010661047      024043
      0188280314      0010661047      027075
      0188280314      0010667463      024019
      0188280314      0010667463      024032
      0188280314      0010667463      024043
      0188280314      0010684834      000000
      0188280314      0010684834      001094
            ...........           ...............       ...........
            ...........           ...............       ...........
            ...........           ...............       ...........
            ...........           ...............       ...........

I want to distinct (or group by) on RWSHID and RISUID and select last JOBCODE in each row.
Would you please send me the query run in Oracle (PL/SQL)

Thanks
-FA


Oracle DatabaseSQL

Avatar of undefined
Last Comment
Guy Hengel [angelIII / a3]
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dqmq
dqmq
Flag of United States of America image

>I want to distinct (or group by) on RWSHID and RISUID and select last JOBCODE in each row.

But there is only one JOBCODE in each row.
And what do you mean by "last"; there is no date in evidence

Is this what you mean:

Select  RWSHID, RISUID max(JOBCODE) group by  RWSHID,  RISUID              
Avatar of Guy Hengel [angelIII / a3]
you might want to read this article: https://www.experts-exchange.com/A_3203.html
will also show how to do it (with row_number() function)

this will be very useful if you need other rows also from the same table.
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo