×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Qualifying by subquery on multiple fields

Qualifying by subquery on multiple fields

Qualifying by subquery on multiple fields

(OP)
Don't know if this is possible but thought I would throw this out there for some help.

I have the following query that I am having trouble with. My problem is that the way the table (Inventory_Item_Fact) is laid out there are multiple rows for the same drug based on inventory received from our wholesaler and prescriptions filled. I am trying to find the record that has the most current date and the quantity on hand at that time. Finding the most current date is easy, it's finding the quantity associated with that date is what I am having problems with. I figure that by using the drug_key and max(date_key) I could find the associated quantity but can't figure out how to join a subquery on two different fields.

Hope this makes sense.

SELECT
TREXONE_DW_DATA.DRUG.DRUG_LABEL_NAME,
TREXONE_DW_DATA.DRUG.DRUG_NDC,
TREXONE_DW_DATA.DRUG.DRUG_PACKAGE_SIZE,
TREXONE_DW_DATA.DRUG.DRUG_DOSAGE_FORM,
TREXONE_DW_DATA.INVENTORY_ITEM_FACT.CURRENT_QTY,
TREXONE_DW_DATA.INVENTORY_ITEM_FACT.DATE_KEY
FROM
TREXONE_DW_DATA.DRUG
INNER JOIN TREXONE_DW_DATA.INVENTORY_ITEM_FACT ON TREXONE_DW_DATA.INVENTORY_ITEM_FACT.DRUG_KEY = TREXONE_DW_DATA.DRUG.DRUG_KEY
WHERE
TREXONE_DW_DATA.DRUG.DRUG_ROUTE = 'OPHTHALMIC' AND
TREXONE_DW_DATA.DRUG.DRUG_OBSOLETE_DATE IS NULL AND
TREXONE_DW_DATA.INVENTORY_ITEM_FACT.FD_FACILITY_KEY = '510'
GROUP BY
TREXONE_DW_DATA.DRUG.DRUG_LABEL_NAME,
TREXONE_DW_DATA.DRUG.DRUG_NDC,
TREXONE_DW_DATA.DRUG.DRUG_PACKAGE_SIZE,
TREXONE_DW_DATA.DRUG.DRUG_DOSAGE_FORM,
TREXONE_DW_DATA.INVENTORY_ITEM_FACT.CURRENT_QTY

flush

DBAMJA

It is said that God will give you no more than you can handle. I just wish God didn't have so much faith in me.

RE: Qualifying by subquery on multiple fields


We don't see any tables.
We don't see any data.
We don't see ant expected results.
...
We can't help you.
nosmiley

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close