计算出现的位置

时间:2014-03-22 17:26:56

标签: php mysql

SELECT serial, model, owner, COUNT(*) AS occurrences 
FROM cars
GROUP BY serial WHERE owner = 'Mike'
ORDER BY occurrences DESC 
LIMIT 5

如何修改此查询以实际工作?我想计算Mike拥有的5个最常见的序列号,并显示模型 - 所有者 - 现场连续数据的数量。

1 个答案:

答案 0 :(得分:0)

您必须更改WHERE子句和GROUP BY的顺序。

试试这个:

  SELECT serial, model, owner, COUNT(*) AS occurrences 
  FROM cars
  WHERE owner = 'Mike'
  GROUP BY serial 
  ORDER BY occurrences DESC 
  LIMIT 5