group by 후 order by 질문드립니다.

group by 후 order by 질문드립니다.

QA

group by 후 order by 질문드립니다.

본문

 

1. 이틀간 검색어를 가져온다

2. pp_word 로 묶어서 카운팅한다

3. 카운팅 값이 같으면 최근에 검색된 순으로 먼저 정렬한다.

 

위의 조건의 쿼리를 아래와 같이 짰습니다.

 

select pp_word, max(pp_id), count(*) as cnt from g5_popular where pp_date BETWEEN DATE_ADD(NOW(),INTERVAL -2 day) AND NOW() group by pp_word order by cnt desc, pp_id DESC, pp_word limit 0, 10

 

근데.. 3번이 제대로 안되는데..

group by pp_word 로 해서 order by cnt desc, pp_id desc 로 하면

되는거 아닌가요?ㅠㅠ

이 질문에 댓글 쓰기 :

답변 2

max(pp_id) 에 max(pp_id) as pp_id 를 추가해 보세요 

select pp_word, max(pp_id) as pp_id, count(*) as cnt from g5_popular where pp_date BETWEEN DATE_ADD(NOW(),INTERVAL -2 day) AND NOW() group by pp_word order by cnt desc, pp_id DESC, pp_word limit 0, 10

쿼리문에는 이상이 없어 보이는데요...

 

select pp_word, max(pp_id) as max_id, count(*) as cnt from g5_popular where pp_date BETWEEN DATE_ADD(NOW(),INTERVAL -2 day) AND NOW() group by pp_word order by cnt desc, max_id DESC  limit 0, 10

 

이렇게 해보세요..

 

전 이상없이 나오네요..

 

2105709021_1534180946.8513.png

 

답변을 작성하시기 전에 로그인 해주세요.
전체 123,475 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT