Commit 0b8eb61f authored by 董国亮's avatar 董国亮

优化查询

parent 989920d6
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
<mapper namespace="net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper"> <mapper namespace="net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper">
<select id="selectByGreenId" resultType="net.wanji.opt.po.StrategyGreenOptHistEntity" parameterType="String" > <select id="selectByGreenId" resultType="net.wanji.opt.po.StrategyGreenOptHistEntity" parameterType="String" >
select * from t_strategy_green_opt_hist where `green_id` = #{greenId} and `control_method`=1 and TIMESTAMPDIFF(SECOND,`control_time`, now()) &lt; `control_duration` order by create_time desc limit 2; select * from t_strategy_green_opt_hist a
inner join (
-- 先查询出最后一条数据的时间
select `green_id`, MAX(`control_time`) control_time from t_strategy_green_opt_hist group by `green_id`
) b on a.`green_id` = b.`green_id` and a.`control_time` = b.`control_time` and a.`green_id` = #{greenId} and a.`control_method` = 1 and TIMESTAMPDIFF(SECOND,a.`control_time`, now()) &lt; a.`control_duration`
</select> </select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment