Query with multiple tables

From: Don (donw_at_mweco.com)
Date: 10/19/04

  • Next message: Don: "Re: Query with multiple tables"
    Date: Tue, 19 Oct 2004 14:33:02 -0500
    
    

    I have what is probably a simple query, but I can't get anything to
    work.

    I have three tables.

    Table one(t1).

    Item, Description, product group, ........
    111 My item 43
    222 Another item 44

    Table two(t2):

    Item, location, qty_on_hand
    111 1 12
    111 2 4
    222 1 20
    222 2 10

    Table three(t3):

    Item, location, year, month, sales
    111 1 2004 1 10.00
    111 1 2004 2 20.00
    111 1 2004 3 30.00
    111 2 2004 1 1.00
    111 2 2004 2 2.00
    111 2 2004 3 3.00
    222 1 2004 1 1.00
    222 1 2004 2 2.00
    222 1 2004 3 3.00

    For each item in table one, there could be many records in table two and
    many in table 3.

    Looking for a query that will return.

    Item Description Location YTD SALES QTY ON HAND
    111 My item 1 60.00 12
    111 My item 2 6.00 4
    222 Another item 1 6.00 20
    222 Another item 2 0 10

    Seems like it should be simple, but I am stuck. There are obviously
    many more items, a few more locations,
    and last year and this year in table 3. I am getting very large numbers
    in my YTD SALES fields.

    The basics of the statement I am using is like this.

    Select distinct
    t1.item, t1.description, t2.location,
    (select distinct sum (t3.sales from t3
      join t3 on t1.item = t3.item
      join t2 on t1.item = t2.item
      where t3.year = '2004' and t3.year = t2.location) as 'YTD SALES',
    t2.qty_on_hand as 'QTY ON HAND'

    Any help would be appreciated.

    Thanks, Don


  • Next message: Don: "Re: Query with multiple tables"

    Relevant Pages

    • Re: adding a text string to data from one field in one database to another
      ... After running the other create table query, ... I have items with price breaks a various quantity levels each ... Qty price at that qty price for that qty ... In the database the data needs to be entered into a field (not ...
      (comp.databases.ms-access)
    • Re: adding a text string to data from one field in one database to another
      ... After running the create table query, I save Table A as text file, TAB ... I have items with price breaks a various quantity levels each of the ... Qty price at that qty price for that qty ... In the database the data needs to be entered into a field (not in ...
      (comp.databases.ms-access)
    • RE: Calculations in queries
      ... 1st: PartName ... Qty ... inventory transaction table and is where I am calculating Parts on Hand. ... The second query has 4 "columns" ...
      (microsoft.public.access.queries)
    • RE: Calculations in queries
      ... Then in qry 2 I just calculate the amount short, without adding the criteria ... THen I built a 3rd query in which I could put the criteria (once it was not ... Qty ... inventory transaction table and is where I am calculating Parts on Hand. ...
      (microsoft.public.access.queries)
    • Re: probably not as complex as Im thinking...
      ... > TotalUnits to see if I was somehow summing the Qty fields wrong, ... > 1, for instance, even though there were defects, just not ones that resulted ... >>rgrantz wrote: ... >>>SQL view and save the query. ...
      (microsoft.public.access.queries)

    Loading