Jump to content

Complicated


johnsmith153

Recommended Posts

 

I have inherited this database and can't change the design.

 

I need to perform a SELECT query and group certain records together for matching employeeID values.

 

The fields:

employeeID

field1

field2

date

 

(1) field1 can be 1,2,3,4 or 5 only

 

(2) field2 can be a,b,c or a number from 1-100 (varchar though)

 

(3) if field1 and field2 are blank/empty then group together

 

 

So:

 

employeeID / field1 / field2 / date

 

32 / 3 /  /  1297184426

45 /  /  b  /  1248723499

32 / 3 /  /  1258762988

20 /  /  / 

20 /  /  /  1268722384

 

 

So record 1 and 3 above will be grouped, and so will 4 and 5.

 

When I mean grouped, I mean so that only one record will be returned / displayed.

 

Also, when it displays only one record due to being 'grouped', I would like it to return the highest 'date' field value (UNIX Timestamp value) (so the newest / latst date) OR if one of the records is empty then show this instead. So in the above example, record 1 & 3 will return a date of 1297184426 and records 4 and 5 will return nothing for date.

Link to comment
Share on other sites

1.)Your definition of grouped;

if field1 and field2 are blank

 

and what you said were grouped;

So record 1 and 3 above will be grouped

 

is not the same. (both fields are not empty)

 

2.)Do you know all the unique employeeID's so you can run a query from a list?

 

3.)If 32 / 3 /  /  1297184426 is in a group and 20 /  /  /  1268722384 is in a group,

what is 20 / 3 / b /  1268722384 a different group or part of the second example?

 

4.) can you modify this database?

 

5.)can you create a temporary database for your own use?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.