记录一下常用的sql语句

求和并且四舍五入

SELECT ROUND(SUM(cost_vue),2) FROM gao_cost where 1=1;

mybatis循环,in语句

<if test="integer_array != null">
		and org_id IN
	<foreach collection="integer_array" item="id" index="index"
		open="(" close=")" separator=",">
         #{id}
	</foreach>
</if>

递归查询父ID下的所有数据的sql

SELECT level, DATA.* FROM(
		SELECT
		@ids as _ids,
		( SELECT @ids := GROUP_CONCAT(dic_id)
		FROM gao_dic
		WHERE FIND_IN_SET(parent_id, @ids)
		) as cids,
		@l := @l+1 as level
		FROM gao_dic,
		(SELECT @ids :=#{dic_id}, @l := 0 ) b
		WHERE @ids IS NOT NULL
		) dic_id, gao_dic DATA
		WHERE parent_id!=0 and  FIND_IN_SET(DATA.dic_id, _ids)
		ORDER BY level, dic_id;

sql语句下的两种查询时间区间的方式

#第一种
<if test="start_task_end_time != null and start_task_end_time != ''"> 
	AND task_end_time <![CDATA[ >=  ]]>#{start_task_end_time}
</if>
<if test="end_task_end_time != null and end_task_end_time != ''"> 
	AND task_end_time <![CDATA[ <=  ]]>#{end_task_end_time}
</if>
#第二种
<if test="tijiao_start_time != null">
	and project_time &gt;= #{tijiao_start_time}
</if>
<if test="tijiao_end_time != null">
	and project_time &lt;= #{tijiao_end_time}
</if>

根据角色-员工-菜单以及中间表查询的权限菜单sql语句,并且去除多角色的重复菜单

select distinct(m.menu_id),m.menu_name,m.menu_link,m.parent_id,m.menu_target from
		heat_employee e LEFT JOIN heat_employee_role er ON e.employee_id=er.employee_id
		LEFT JOIN heat_role r ON er.role_id=r.role_id
		LEFT JOIN heat_role_menu rm ON
		r.role_id=rm.role_id
		LEFT JOIN heat_menu m ON rm.menu_id=m.menu_id
		<where>
			1=1
			<if test="employee_id != null">
				and e.employee_id=#{employee_id}
			</if>
			<if test="parent_id_no != null">
				AND m.parent_id !=0
			</if>
			<if test="parent_id == 0">
				AND m.parent_id =0
			</if>
			<if test="parent_id != null">
				AND m.parent_id =#{parent_id}
			</if>
			<if test="menu_leave != null">
				AND m.menu_leave =#{menu_leave}
			</if>
			<if test="menu_state != null">
				AND m.menu_state =#{menu_state}
			</if>
			<if test="menu_type != null">
				AND m.menu_type =#{menu_type}
			</if>
		</where>
		ORDER BY m.menu_sort ASC

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一城烟雨lxf

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

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

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

打赏作者

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

抵扣说明:

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

余额充值