어떻게 연합체에 연합체를 설치합니까?

4

질문:

다음 코드를 실행하려고 합니다.
SELECT ItName, ItCode, Qty, Qt2, Qt3
FROM
(
SELECT A.ItName, A.ItCode, COUNT(B.Qty) AS 'Quantity 1', COUNT(B.Qty2) AS 'Quantity 2', 
COUNT(B.Qty3) AS 'Quantity 3' 
FROM tblitem A
INNER JOIN tblstocksummary B ON A.ItCode = B.ItCode
WHERE A.Itcode='IL001-000151'
GROUP BY A.ItCode
HAVING COUNT(B.Qty) !='0'AND COUNT(B.Qty2) !='0' AND COUNT(B.Qty3) !='0'

UNION

SELECT A2.ItName, A2.ItCode, COUNT(B2.Qty), COUNT(B2.Qty2), COUNT(B2.Qty3) FROM tblitem A2
INNER JOIN tblstocksummary B2 ON A2.ItCode = B2.ItCode
WHERE A2.Itcode='IL001-000373' 
GROUP BY A2.ItCode
HAVING COUNT(B2.Qty) !='0'AND COUNT(B2.Qty2) !='0' AND COUNT(B2.Qty3) !='0'
) t
UNION ALL

SELECT A3.ItName, A3.ItCode, COUNT(B3.Qty), COUNT(B3.Qty2), COUNT(B3.Qty3) FROM tblitem A3
INNER JOIN tblstocksummary B3 ON A2.ItCode = B3.ItCode
WHERE A3.Itcode='IL001-000166' 
GROUP BY A3.ItCode
HAVING COUNT(B3.Qty) !='0'AND COUNT(B3.Qty2) !='0' AND COUNT(B3.Qty3) !='0';
하지만 내게 잘못이 하나 있다.

SQL Error(1054): Unknown column 'Qty' in field list


그래서 나는 내가 잘못된 문법을 사용했든지, 아니면 할 수 없는 일을 하려고 시도했든지 추측했다.아마도 가장 경험이 많은 사람은 바로 문제의 소재를 발견할 것이다.
도와줄 사람 있어요?감사합니다.너 때문에

답안

수량이 아니라 열로
그렇게 지도 모른다, 아마, 아마...
SELECT ItName, ItCode, Qty, Qt2, Qt3
FROM
(
SELECT A.ItName, A.ItCode, COUNT(B.Qty) AS 'Qty', COUNT(B.Qty2) AS 'Qty2', 
COUNT(B.Qty3) AS 'Qty3' 
FROM tblitem A
INNER JOIN tblstocksummary B ON A.ItCode = B.ItCode
WHERE A.Itcode='IL001-000151'
GROUP BY A.ItCode
HAVING COUNT(B.Qty) !='0'AND COUNT(B.Qty2) !='0' AND COUNT(B.Qty3) !='0'

UNION

SELECT A2.ItName, A2.ItCode, COUNT(B2.Qty), COUNT(B2.Qty2), COUNT(B2.Qty3) FROM tblitem A2
INNER JOIN tblstocksummary B2 ON A2.ItCode = B2.ItCode
WHERE A2.Itcode='IL001-000373' 
GROUP BY A2.ItCode
HAVING COUNT(B2.Qty) !='0'AND COUNT(B2.Qty2) !='0' AND COUNT(B2.Qty3) !='0'
) t
UNION ALL

SELECT A3.ItName, A3.ItCode, COUNT(B3.Qty), COUNT(B3.Qty2), COUNT(B3.Qty3) FROM tblitem A3
INNER JOIN tblstocksummary B3 ON A2.ItCode = B3.ItCode
WHERE A3.Itcode='IL001-000166' 
GROUP BY A3.ItCode
HAVING COUNT(B3.Qty) !='0'AND COUNT(B3.Qty2) !='0' AND COUNT(B3.Qty3) !='0';