【问题标题】:MySQL: Select rows with more than one occurrenceMySQL:选择多次出现的行
【发布时间】:2010-11-22 06:51:31
【问题描述】:

这是我的问题。它从两个数据库中的两个表中选择一个 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

【问题讨论】:

    标签: mysql


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多