数据库格式:
需求:根据area分组并统计分组后的总数,根据统计出来的总数降序排序,获取前10条数据。
<select id="selectByAreaDevNumList" resultMap="BaseResultMap" parameterType="java.util.List" >
select
area ,COUNT(*)
from car_area
where dev_num IN
<foreach collection="list" item="list" open="(" separator="," close=")">
#{list}
</foreach>
GROUP BY area
order by COUNT(*)
DESC LIMIT 10
</select>
mysql中的代码获取如下:
SELECT area ,COUNT(*)
FROM car_area
GROUP BY area
order by COUNT(*)
DESC LIMIT 0,10
或者可以这么写
SELECT area ,COUNT(*)
FROM car_area
GROUP BY area
order by COUNT(*)
DESC LIMIT 10
运行结果如下: