··조회 12,198
쿼리 질문입니다 mysql
select max(no) as no from bbs where no <= 4000
union
select min(no) as no from bbs where no >= 6000
order by no desc
+------+
| no |
+------+
|6000 |
| 4000 |
+------+
이런식으로 되어있는 쿼리에다 title정보까지 뽑아오고 싶은데 어떻게 해야하나요
select max(no) as no,title from bbs where no <= 4000
union
select min(no) as no,title from bbs where no >= 6000
order by no desc
ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause
서브쿼리를 사용하고 싶지만 4.0버전이라 지원이 안됩니다
union
select min(no) as no from bbs where no >= 6000
order by no desc
+------+
| no |
+------+
|6000 |
| 4000 |
+------+
이런식으로 되어있는 쿼리에다 title정보까지 뽑아오고 싶은데 어떻게 해야하나요
select max(no) as no,title from bbs where no <= 4000
union
select min(no) as no,title from bbs where no >= 6000
order by no desc
ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause
서브쿼리를 사용하고 싶지만 4.0버전이라 지원이 안됩니다
댓글 2
원래 max 나 min 과 같이 그룹을 대상으로 계산하는 함수를 사용할 경우 다른 컬럼명과 함께 사용할 수 없습니다.
질문하신 분 말마따나 서브쿼리도 사용할 수 없구...
글쎄요. 저도 좀 더 고민을 해봐야겠습니다.
지금 당장 답변을 드리지 못해 죄송합니다.
select no,title from bbs where no <= 4000 ORDER BY no DESC;
원하시는 결과는 나올 것 같은데요^^