优化:优化 SQL 语句风格

1.MySQL数据库>SQL语句>第10条:
【推荐】SQL 语句中表的别名前加 as,并且以 t1、t2、t3、...的顺序依次命名。
说明:
  1)别名可以是表的简称,或者是依照表在 SQL 语句中出现的顺序,以 t1、t2、t3 的方式命名。
  2)别名前加 as 使别名更容易识别。
正例:select t1.name from first_table as t1 , second_table as t2 where t1.id = t2.id
个人理解:使用 t1、t2、t3... 的表别名命名方式,在很多类似业务查询的场景会更方便复用;使用 AS 而不是 as 更容易阅读。
This commit is contained in:
2023-03-10 23:17:25 +08:00
parent 5b50303a91
commit 2d71af9efb
2 changed files with 24 additions and 27 deletions

View File

@@ -2,14 +2,11 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.charles7c.cnadmin.system.mapper.RoleMenuMapper">
<select id="selectMenuIdByRoleIds" resultType="java.lang.Long">
SELECT
`menu_id`
SELECT `menu_id`
FROM `sys_role_menu`
<where>
`role_id` IN
<foreach collection="list" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
</where>
WHERE `role_id` IN
<foreach collection="list" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
</select>
</mapper>