SELECT memberno, MIN(ju), point
FROM
(
SELECT memberno, MIN(junno) AS ju, SUM(VD_money1 - membpoint) AS point
FROM outm_1805
GROUP BY memberno
UNION
SELECT memberno, MIN(junno) AS ju, SUM(VD_money1 - membpoint) AS point
FROM outm_1806
GROUP BY memberno
UNION
SELECT memberno, MIN(junno) AS ju, SUM(VD_money1 - membpoint) AS point
FROM outm_1807
GROUP BY memberno
) a
GROUP BY memberno --, point
ORDER BY memberno
memberno ju point
38000379 2018-05-2810152 4834.00
38000386 2018-06-0410177 13600.00
38000416 2018-06-1210086 881.00
위처럼 각 TABLE 마다 memberno를 GROUP으로 묶어서 가장낮은 ju 만 찾으려고 하는데 point 를 GROUP에 포함시키면
아래처럼 모든 ju 가 출력되요
memberno ju point
38000379 2018-05-2810152 4834.00
38000379 2018-07-2110059 28752.00
38000379 2018-06-0110217 45968.51
38000386 2018-07-0610060 4104.00
38000386 2018-06-0410177 13600.00
38000416 2018-06-1210086 881.00
38000416 2018-07-0410205 2118.32
point를 GROUP으로 묶지않으면 에러가 뜹니다 point 까지 출력할수있는 방법이 있나요?
Column 'a.point' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. |