我应该使用哪个MySQL查询来重复X次行?
示例(愚蠢的一个^^):
John likes apples.
Dave likes apples.
Bough likes bananas.
Light likes apples.
Wiky likes bananas.
我想要一个只返回3人喜欢的水果的查询(在我的例子中是苹果)。 干杯!
答案 0 :(得分:3)
我想要一个只返回的查询 3人喜欢的水果(我的苹果) 例如)
试试这个:
SELECT fruit_name FROM `table` group by fruit_name having count(fruit_name)>=3;
答案 1 :(得分:2)
如果“地址”是您定义2行是否相同的列,那么:
select address, count(address) as cnt from mailing_list group by address having cnt = $x order by cnt;
答案 2 :(得分:0)
如果您要计算列的每个重复行:
select count(*), column1 from table group by column
如果要重复,请将“列”指定为您想知道的列。如果要查看是否重复了多个列,请用逗号分隔。
select count(*), column1, column2 from table group by column1,column2
编辑:
如果你想获得只有X重复的行:
select c, column1 from (select count(*) as c, column1 from table group by column1) where c = X