제가 지금 하려는 거는 it_model 값이 중복으로 있는 것들만 모두 출력하려고 합니다.
그래서
Copy
select *, COUNT(*) AS nums
$sql_common
and it_model !='' GROUP BY it_model HAVING nums > 1
$sql_order
limit $from_record, $rows
이렇게 했더니 중복되는 애들 중에 하나만 나옵니다.
어떻게 바꾸면
it_model 값이 중복되는 애들이 모~두 나올까요?
|
답변 1개 / 댓글 5개
채택된 답변
+20 포인트
2020-04-16 (목) 11:04:26
select * from $sql_common
and it_model in (
select it_model
from $sql_common
and it_model <> ''
group by it_model
having count(it_model) > 1
)
$sql_order
limit $from_record, $rows
-----------
위와같이 변경해서 한번 실행해보시죠
답변에 대한 댓글 5개
2020-04-16 (목) 14:03:53
2020-04-16 (목) 14:42:14
select *, COUNT(*) AS nums
from g5_shop_item
where (1) and it_model !='' GROUP BY it_model HAVING nums > 1
order by it_id desc
입니다.
(limit 뒤에는 생략했습니다.)
from g5_shop_item
where (1) and it_model !='' GROUP BY it_model HAVING nums > 1
order by it_id desc
입니다.
(limit 뒤에는 생략했습니다.)
2020-04-16 (목) 16:00:52
@뜨악뜨악
제가 만들어드린 쿼리가 정상적으로 작동하는데요
참고로.. group by 에 * 하면 나오는게 제한됩니다.
서브쿼리로 풀어야 정상입니다.
SELECT * FROM g5_shop_item
where it_model IN (select it_model
from g5_shop_item
where it_model !=''
GROUP BY it_model
HAVING COUNT(*) > 1
)
order by it_id desc
이걸로 한번 확인해보세요
제가 만들어드린 쿼리가 정상적으로 작동하는데요
참고로.. group by 에 * 하면 나오는게 제한됩니다.
서브쿼리로 풀어야 정상입니다.
SELECT * FROM g5_shop_item
where it_model IN (select it_model
from g5_shop_item
where it_model !=''
GROUP BY it_model
HAVING COUNT(*) > 1
)
order by it_id desc
이걸로 한번 확인해보세요
답변을 작성하려면 로그인이 필요합니다.
저도 저런식으로 시도를 해봣엇는데 ㅠ
흑 ㅠ