关联更新和关联插入sql

关联插入Mysql

// codeType传入值,@rowno 获取每行,可以去掉,codeNum定义的值
insert into sys_upload_file (name, code)
	select b.name,concat(#{codeType},@rowno:=@rowno+1) code
	from dat_goods a, gds_goodscontrast b ,(select @rowno:=#{codeNum}) t
	where a.id = b.goodsId 

关联更新Mysql

update temp a INNER JOIN (
select id,(case when inventoryQuantity is null then 0 else 0-inventoryQuantity end), 
lostOrIncomeQuantity from temp2 ) b on a.id = b.id
set 
a.lostOrIncomeQuantity = b.lostOrIncomeQuantity

mysql 字符串处理相关截取

SELECT SUBSTRING_INDEX('aMc','M',-1)

SELECT REVERSE(LEFT(REVERSE('test.htm'),INSTR(REVERSE('test.htm'),'.')))

SELECT LOCATE('M', 'LF1212 石基(黑砂) 1000×1000mm')
SELECT REVERSE('abc')

SELECT substring( REVERSE('abc'),1,LOCATE(' ', REVERSE('abc)'))-1),REVERSE('abc')
(case 
when ifnull(g.smallUnit,'')<>'' && ifnull(d.smallUnit,'')<>'' && g.smallUnit=d.smallUnit  then g.produce 
 else 0 end)

Mybatis—动态查询(choose,when,otherwise)
choose (when, otherwise)标签
有时候我们并不想应用所有的条件,而只是想从多个选项中选择一个。而使用if标签时,只要test中的表达式为 true,就会执行 if 标签中的条件。MyBatis 提供了 choose 元素。if标签是与(and)的关系,而 choose 是或(or)的关系。

choose标签是按顺序判断其内部when标签中的test条件出否成立,如果有一个成立,则 choose 结束。当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的sql。类似于Java 的 switch 语句,choose 为 switch,when 为 case,otherwise 则为 default。

<select id="dynamicChooseTest" parameterType="Blog" resultType="Blog">
        select * from t_blog where 1 = 1 
        <choose>
            <when test="title != null">
                and title = #{title}
            </when>
            <when test="content != null">
                and content = #{content}
            </when>
            <otherwise>
                and owner = "owner1"
            </otherwise>
        </choose>
    </select>


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值