Unix Technical Forum

Select record with highest value for field hours from multiple rows

This is a discussion on Select record with highest value for field hours from multiple rows within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hello, I've got a table with the following columns: EmployeeNumber, Company, Department, Cluster, Job, Hours There can be multiple ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 10:16 AM
willy
 
Posts: n/a
Default Select record with highest value for field hours from multiple rows

Hello,

I've got a table with the following columns:
EmployeeNumber, Company, Department, Cluster, Job, Hours

There can be multiple records for one EmployeeNumber.
An employee can work for multiple companies, for multiple departments
within a company, for multiple clusters within a department or can have
multiple jobs within a cluster.

So, there can be multiple jobs for a specific combination of
EmployeeNumber, Company, Department and Cluster.
I want to create a view that selects only one record per
EmployeeNumber, Company, Department, Cluster combination. It has to
select the job that has the highest value for the field Hours.

How can I do that?

Kind regards,

Willy Tadema

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 10:16 AM
Mark D Powell
 
Posts: n/a
Default Re: Select record with highest value for field hours from multiple rows


willy wrote:
> Hello,
>
> I've got a table with the following columns:
> EmployeeNumber, Company, Department, Cluster, Job, Hours
>
> There can be multiple records for one EmployeeNumber.
> An employee can work for multiple companies, for multiple departments
> within a company, for multiple clusters within a department or can have
> multiple jobs within a cluster.
>
> So, there can be multiple jobs for a specific combination of
> EmployeeNumber, Company, Department and Cluster.
> I want to create a view that selects only one record per
> EmployeeNumber, Company, Department, Cluster combination. It has to
> select the job that has the highest value for the field Hours.
>
> How can I do that?
>
> Kind regards,
>
> Willy Tadema


And you tried to solve this how?

You can easily get one for per EmployeeNumber, Comapny, Deparment,
Cluseter by using a group by and the use of a group by clause would
allow you to find the MAX(hours) per group. Unfortunately, I think you
will get a "not a group by column" error if you try to select job along
with this.

But since you know the EmployeeNumber, Company, Department, Cluster,
and Hours for the row you want I would think a join back to the
original table on these columns would find the associated job.

That would be one way to go about solving this problem. I will leave
the actual SQL to you.

HTH -- Mark D Powell --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 10:16 AM
DA Morgan
 
Posts: n/a
Default Re: Select record with highest value for field hours from multiplerows

willy wrote:
> Hello,
>
> I've got a table with the following columns:
> EmployeeNumber, Company, Department, Cluster, Job, Hours
>
> There can be multiple records for one EmployeeNumber.
> An employee can work for multiple companies, for multiple departments
> within a company, for multiple clusters within a department or can have
> multiple jobs within a cluster.
>
> So, there can be multiple jobs for a specific combination of
> EmployeeNumber, Company, Department and Cluster.
> I want to create a view that selects only one record per
> EmployeeNumber, Company, Department, Cluster combination. It has to
> select the job that has the highest value for the field Hours.
>
> How can I do that?
>
> Kind regards,
>
> Willy Tadema


This is clearly school work. Post your best attempt and we will give
you pointers ... not solutions.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 10:17 AM
joel garry
 
Posts: n/a
Default Re: Select record with highest value for field hours from multiple rows


DA Morgan wrote:

> This is clearly school work. Post your best attempt and we will give
> you pointers ... not solutions.


That may well be true, but I feel compelled to point out that I had a
very similar requirement in the real world. (Although, I didn't solve
it with a view. As part of a barcoding/job cost tracking system, the
program mails appropriate managers when people obviously forget to
clock out of a job - or, as happened recently, the UPS screws up and
they can't clock out and no one has access to voice mail or email
and...)

So do your schoolwork folks, don't expect usenet to bail you out! It
pays off in the real world.

jg
--
@home.com is bogus. "The sad truth is the job pays too well - I am an
Oracle whore and Larry is my pimp. In order for me to be truely happy
in my job I must master my fears and really get to grips with Oracle -
it's architecture and the strange gubbins inside the mysterious
machine." - Alan Barton

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 10:17 AM
kes
 
Posts: n/a
Default Re: Select record with highest value for field hours from multiple rows

joel garry wrote:
<snip>
> So do your schoolwork folks, don't expect usenet to bail you out! It
> pays off in the real world.


Isn't it great that school is back in session?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:39 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com