2014-04-21 2 views
0

여기에 내가 테이블에 가입하는 문제가 있습니다. 그래서 왼쪽 조인을 시도하고 예외 조건을 얻지 못했습니다. 예외적 인 result.i를 얻지 못했습니다. 그래서 초보자가 mysql을 사용하면 도움이 될 수 있습니다.왼쪽 조인과 mysql의 where 절

쿼리

SELECT 
m.mon, 
m.monthnames, 
d.Outlet_Name, 
e.category_Name, 
f.Department_Name, 
b.Item_Name, 
SUM(a.Item_Qty) AS Qty, 
SUM(a.Net_amount+a.Item_tax1) AS NetAmount 
FROM (
    SELECT 1 AS mon, 'Jan' AS monthnames 
    UNION 
    SELECT 2, 'Feb' 
    UNION 
    SELECT 3, 'Mar' 
    UNION 
    SELECT 4, 'Apr' 
    UNION 
    SELECT 5, 'May' 
    UNION 
    SELECT 6, 'jun' 
    UNION 
    SELECT 7, 'july' 
    UNION 
    SELECT 8, 'Aug' 
    UNION 
    SELECT 9, 'Sep' 
    UNION 
    SELECT 10, 'Oct' 
    UNION 
    SELECT 11, 'NoV' 
    UNION 
    SELECT 12, 'Dec' 
     ) AS monthno 
    LEFT JOIN KOT_Items a 
    ON MONTH(a.tran_date) = m.mon 
    Item_Master b, 
     KOT_Main c, 
     Outlet d, 
     Category_Master e, 
     Department_Master f, 
    WHERE a.Main_Item_Code=b.Item_Code 
    AND e.Category_Code=b.Category_Code 
    AND e.Category_Code =f.Category_Code 
    AND d.Outlet_id = c.outlet_id 
    AND a.ref_no=c.ref_no 
    GROUP BY 
    m.mon, 
    m.monthnames, 
    d.Outlet_Name, 
    e.category_Name, 
    f.Department_Name, 
    b.Item_Name 

예외 처리 결과는 다음과 같이 할 수 있습니다 :

mon monthnames Outlet_Name  netamount 

4 Apr MEXICAN AMIGOS   1 
4 Apr MEXICAN AMIGOS   100 
4 Apr MEXICAN AMIGOS   150 
4 Apr MEXICAN AMIGOS   1500 
4 Apr MEXICAN AMIGOS 
4 Apr MEXICAN AMIGOS 
4 Apr MEXICAN AMIGOS  
4 Apr MEXICAN AMIGOS 
4 Apr MEXICAN AMIGOS 
1 jan 
2 feb 
3 mar 
5 may 
6 june 
7 july 
8 Aug 
9 Sep 
10 Oct 
11 nov 
12 Dec 
+0

모든 아이디어 ?????? – user3331535

+0

왼쪽에있는 모든 내부 조인을 변경하십시오. – Gooner

+0

가능한 경우 쿼리를 업데이트하면 u에서 배울 수 있습니다. ?? – user3331535

답변

0

나는 당신의 테이블 구조 나 요구 사항에 대한 확실하지 않다. 찾고있는 구문이라면 구문을 보여 줬습니다.

SELECT 
m.mon, 
m.monthnames, 
d.Outlet_Name, 
e.category_Name, 
f.Department_Name, 
b.Item_Name, 
SUM(a.Item_Qty) AS Qty, 
SUM(a.Net_amount+a.Item_tax1) AS NetAmount 
FROM (
    SELECT 1 AS mon, 'Jan' AS monthnames 
    UNION 
    SELECT 2, 'Feb' 
    UNION 
    SELECT 3, 'Mar' 
    UNION 
    SELECT 4, 'Apr' 
    UNION 
    SELECT 5, 'May' 
    UNION 
    SELECT 6, 'jun' 
    UNION 
    SELECT 7, 'july' 
    UNION 
    SELECT 8, 'Aug' 
    UNION 
    SELECT 9, 'Sep' 
    UNION 
    SELECT 10, 'Oct' 
    UNION 
    SELECT 11, 'NoV' 
    UNION 
    SELECT 12, 'Dec' 
     ) AS m 
    LEFT JOIN KOT_Items a 
    ON MONTH(a.tran_date) = m.mon 
    LEFT JOIN Item_Master b 
    ON a.Main_Item_Code=b.Item_Code 
    LEFT JOIN KOT_Main c 
    ON a.ref_no=c.ref_no 
    LEFT JOIN Outlet d 
    ON d.Outlet_id = c.outlet_id 
    LEFT JOIN Category_Master e 
    ON e.Category_Code=b.Category_Code 
    LEFT JOIN Department_Master f 
    ON e.Category_Code =f.Category_Code 
    GROUP BY 
    m.mon, 
    m.monthnames, 
    d.Outlet_Name, 
    e.category_Name, 
    f.Department_Name, 
    b.Item_Name