mysql - 带有子查询MySql

标签 mysql count subquery max having-clause

我想选择事故最多的车型。 我正在使用以下查询,但出现语法错误。 请有人告诉我出了什么问题..

    select car.Model 
    from car 
    join car_accident_involved 
       on car.Car_Registration_ID = car_accident_involved.Car_Registration_ID 
    group by car.Model 
    having MAX(
       select COUNT(Car_Registration_ID) 
       from car_accident_involved
    );

最佳答案

您可以在此处使用简单的子查询,例如:

select model from car
where car_registration_id = 
 (select car_registration_id
  from car_accident_involved
  group by model 
  order by count(car_registration_id) desc
  limit 1);

关于mysql - 带有子查询MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36241848/

相关文章:

python - 在mysql中获取自动递增的行ID的时间复杂度

mysql - 计算和分组 MySQL 中的非空值

caching - 18M+ 行表的子查询和 MySQL 缓存

mysql - 如何将子查询作为参数传递给 MySQL 过程?

MySQL Order by 在 View 中的 group by 之前(无子查询)

python - 奇怪的 MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) 问题

javascript - 何时使用 node-mysql 关闭 MySQL 连接?

python - 有没有一种优雅的方法可以在 python 中使用 lxml 来计算 xml 文件中的标记元素?

mysql - Django、MySQL;加载 MySQLdb 模块时出错

mysql - 根据计数标准在 MySQL 中选择行时出错