个人笔记12

这篇笔记涵盖了数据库查询技巧,包括正确处理分组排序的方法,时区转换以及SQL查询当前时间区间数据。还介绍了Linux常用命令,如创建目录、重命名、grep查询,以及Java内存溢出处理和Jedis与Redisson的区别。
摘要由CSDN通过智能技术生成

在这里插入图片描述
表数据如上。现在要求查询的列表为按outline_group_id分组,分组后组内按照sort_no排序
错误的做法:
这样只能得到分组的第一条记录

  <select id="selectByOutlineGroupIdsAndStudentId"  resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from homework_student_answer
    where outline_group_id in
    <foreach collection="list" separator="," item="item" index="index" close=")" open="(">
      #{item,jdbcType=INTEGER}
    </foreach>
    and student_user_id = #{studentId,jdbcType=BIGINT}
  group by outline_group_id  order by sort_no
  </select>

正确的做法:

  <select id="selectByOutlineGroupIdsAndStudentId"  resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from homework_student_answer
    where outline_group_id in
    <foreach collection="list" separator="," item="item" index="index" close=")" open="(">
      #{item,jdbcType=INTEGER}
    </foreach>
    and student_user_id = #{studentId,jdbcType=BIGINT}
    order by outline_group_id,sort_no
  </select>

  即:
SELECT
	*
FROM
	homework_student_answer
WHERE
	outline_group_id IN (
		336,
		337,
		338,
		339,
		340,
		341,
		342,
		343,
		348
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

万米高空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值