how to add quantity of items and match

Discussion in 'Databases' started by arman28, Feb 16, 2010.

  1. #1
    I have two tables, Import and Export, looking like this;
    Import Date | Shoe Style | Shoe Color | Quantity |
    ------------|------------|------------|----------|
    11/20/2003 | A2003B | Red | 100 |
    11/19/2003 | A2003B | Red | 20 |
    11/20/2003 | A2005B | White | 80 |
    11/20/2003 | A2003B | Red | 100 |
    11/20/2003 | A2003B | Green | 100 |

    AND

    Export Date | Shoe Style | Shoe Color | Quantity |
    ------------|------------|------------|----------|
    11/20/2004 | A2003B | Red | 100 |
    11/19/2004 | A2003B | Red | 100 |
    11/20/2005 | A2005B | White | 80 |
    11/20/2005 | A2005B | White | 100 |
    11/20/2004 | A2003B | Blue | 100 |

    This is what I need;

    Import Date | Shoe Style | Shoe Color | Quantity |
    ------------|------------|------------|----------|
    11/20/2003 | A2003B | Red | 220 |
    11/20/2003 | A2005B | White | 80 |
    11/20/2003 | A2003B | Green | 100 |

    Next to..

    Export Date | Shoe Style | Shoe Color | Quantity |
    ------------|------------|------------|----------|
    11/20/2004 | A2003B | Red | 200 |
    11/20/2005 | A2005B | White | 180 |
    11/20/2004 | A2003B | Blue | 100 |

    Any suggestions?
     
    arman28, Feb 16, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    SELECT Import_Date,Shoe_Style,Shoe_Color,SUM(Quantity) SUM_Quantity FROM
    ((SELECT * FROM Import)
    UNION ALL
    (SELECT * FROM Export)) A
    GROUP BY Import_Date,Shoe_Style,Shoe_Color
    ORDER BY Shoe_Style,Import_Date;
    
    Code (markup):
    :cool:
     
    koko5, Feb 16, 2010 IP
  3. arman28

    arman28 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the reply. The "Union" gives me the syntax error.
     
    arman28, Feb 16, 2010 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    OK, try this:
    SELECT Import_Date,Shoe_Style,Shoe_Color,SUM(Quantity) SUM_Quantity FROM
    ((SELECT Import_Date,Shoe_Style,Shoe_Color,Quantity FROM Import)
    UNION ALL
    (SELECT Import_Date,Shoe_Style,Shoe_Color,Quantity FROM Export)) A
    GROUP BY Import_Date,Shoe_Style,Shoe_Color
    ORDER BY Shoe_Style,Import_Date;
    
    Code (markup):
    Check your exact column names and paste the errors if any.
    Regards
     
    koko5, Feb 16, 2010 IP
  5. arman28

    arman28 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for wanting to help but I still get the syntax error. Please try it for yourself and see what error you get, maybe that way it is more clear to you what error I get.
     
    arman28, Feb 17, 2010 IP
  6. arman28

    arman28 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I will take any other suggestions if anyone has any????
    I am simply trying to see the number of quantities of the shoes exported and to see if those shoes were ever imported and if so how many were imported, so I will need a table with the following headers;

    Import Date | Import Color | Import Style | Import Qty | Export Date | Export Color | Export Style | Export Qty
    ------------|-------------|-------------|------------|------------|-------------|-------------|------------
     
    arman28, Feb 17, 2010 IP