programing

MySQL: 둘 이상 발생한 행 선택

codeshow 2023. 10. 29. 20:01
반응형

MySQL: 둘 이상 발생한 행 선택

제 질문은 이렇습니다.두 데이터베이스에 걸쳐 두 개의 테이블에서 ID 목록을 선택합니다.쿼리가 정상적으로 작동합니다.

select en.id, fp.blogid
from french.blog_pics fp, french.blog_news fn, english.blog_news en 
where fp.blogid = fn.id 
and en.title_fr = fn.title 
and fp.title != '' 

행을 표시할 때만 다음과 같이 표시합니다.en.id두 번 이상 발생합니다.

예를 들어, 이것이 현재의 쿼리 결과였다면

en.id fp.blogid
---------------
  10     12
  12     8
  17     9
  12     8

대신 이것을 보여주기 위해 쿼리만 하려고 합니다.

 en.id fp.blogid occurrences
 -----------------------------
  12     8           2
select en.id, fp.blogid, count(*) as occurrences
from french.blog_pics fp, french.blog_news fn, english.blog_news en 
where fp.blogid = fn.id 
and en.title_fr = fn.title 
and fp.title != ''
group by en.id
having count(*) > 1

언급URL : https://stackoverflow.com/questions/4242990/mysql-select-rows-with-more-than-one-occurrence

반응형