1.需求是查询user_0表中的所有id,作为user_1表中的name属性值插入,刚开始时在代码中先查询出id 再循环插入表,非常浪费,实际上一条sql语句即可执行
INSERT INTO user_1(name, age, remark)SELECT id, rand()*1, "常量" as col FROM user_0
2.批量修改表名
select CONCAT( 'ALTER TABLE `', table_name, '` RENAME TO `device_', substring(table_name,4),'`;' ) FROM information_schema.tables Where table_name LIKE 'ori_%' AND TABLE_SCHEMA = 'tms'
执行之后会得到修改表名的所有语句,

然后批量执行语句即可
3. ifnull 函数和 case when end 都是处理查询结果集中的某一个字段,并不能针对整个结果集
4.遇到一件事情,left join 一张表的时候,如果没加条件,会巨慢!!
5.<if test="typecode != null and typecode != ''">
<when test=" typecode != 'Z'.toString() ">
AND device.bmwytype IS NOT NULL AND bmwytype != 'Z'
AND device.bmwytype = #{typecode}
</if>
6.java中读取float类型的值的时候如果小数位特别多会是科学计数法的值,需要注意
网友评论