28 lines
761 B
XML
28 lines
761 B
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<!DOCTYPE mapper
|
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="cn.unizk.mapper.DeviceUsageDetailMapper">
|
|
|
|
|
|
<select id="selectTopThree" resultType="cn.unizk.entity.po.DeviceUsageDetail">
|
|
SELECT pl,create_time
|
|
FROM device_usage_detail
|
|
WHERE pl IN (
|
|
SELECT t.pl
|
|
FROM (
|
|
-- 核心逻辑放在这里,作为一张虚拟表
|
|
SELECT pl
|
|
FROM device_usage_detail
|
|
WHERE usage_record_id = #{usageRecordId}
|
|
and status = 2
|
|
GROUP BY pl
|
|
ORDER BY COUNT(*) DESC
|
|
LIMIT 3
|
|
) AS t -- 必须给派生表起别名
|
|
)
|
|
and usage_record_id = #{usageRecordId}
|
|
</select>
|
|
|
|
</mapper>
|