후속 질문이 있습니다. sum of counts of different columns of same table 다른 테이블 (B)의 필드 (Z)를 업데이트하고 싶습니다. 결과 선택 쿼리 (A.COUNT_TOTAL) : 나는 문 다음 시도mySQL의 다른 테이블에서 select 결과를 가진 테이블의 필드를 업데이트하십시오.
SELECT A.ID, SUM(A.COUNTS) AS COUNT_TOTAL
FROM
(
SELECT X AS ID, COUNT(*) AS COUNTS FROM TABLE1 GROUP BY X
UNION ALL
SELECT Y AS ID, COUNT(*) AS COUNTS FROM TABLE1 GROUP BY Y
) A
GROUP BY A.ID
ORDER BY A.ID;`
, (그러나 막연한 오류 메시지가 얻을) :
UPDATE B
INNER JOIN (
SELECT A.ID, SUM(A.COUNTS) AS COUNT_TOTAL
FROM
(
SELECT X AS ID, COUNT(*) AS COUNTS FROM TABLE1 GROUP BY X
UNION ALL
SELECT Y AS ID, COUNT(*) AS COUNTS FROM TABLE1 GROUP BY Y
) A
GROUP BY A.ID) as A on B.ID = A.ID
SET B.Z = A.COUNT_TOTAL
모호한 오류가 발생 했습니까? – CGritton