2013-05-13 2 views
-1

내가 Products_AUNION 2 표,

Product_ID Product_Name Price Quantity 
11   MilkA 36  56 3 
21   MeatB 123 78 23 
31   SugarA 29 45 333 

Products_B

Product_ID Product_Name Price Quantity 
21   MilkB 63  65 33 
22   MeatB 321 87 4345 
23   SugarB 92 54 232 

내가 원하는이

Product_ID Quantity Quantity*Price 
11   36  
21   123 
31   29 
21   63 
22   321 
23   92 

내가 시도 같은 선택 쿼리

SELECT 
    Products_A.Quantity, 
    Products_B.Quantity, 
    Products_A.Quantity * Products_A.Price, 
    Products_B.Quantity*Products_B.Price 
    FROM products_A, 
    products_B; 
이 (그들을 결합)

하지만 서식이 지정되지 않은 것 같습니다. 세부 사항

+0

SQL 쿼리에서 UNION을 검색하십시오! – goseo

답변

2

두 테이블의 결과를 모두 보려면 UNION ALL을 사용할 수 있습니다.

SELECT 
    a.Product_Id as product_Id, 
    a.Quantity, 
    a.Quantity * a.Price as total 
FROM Products_A a 
UNION ALL 
SELECT 
    b.Product_Id as product_Id, 
    b.Quantity, 
    b.Quantity * b.Price as total 
FROM Products_B b 
+0

라파엘, b에서 쉼표를 잊어 버렸습니다.하지만 이것은 미래의 방문자를위한 것입니다. – user2377214