随笔分类 -  mysql

摘要:select a.* from table a where 10 > (select count(*) from table b where b.dif_distance = a.dif_distance and b.id > a.id ) order by a.id-- 按照dif_distanc 阅读全文
posted @ 2022-06-13 10:54 远启 阅读(2670) 评论(1) 推荐(0) 编辑
摘要:1.判断数据是否存在 -- 通常写法,查出条件下的数据数量count SELECT count(*) FROM table WHERE a = 1 AND b = 2 2.提升效率写法 -- 使用Limit1 , 避免资源过度扫描 SELECT 1 FROM table WHERE a = 1 AN 阅读全文
posted @ 2021-11-22 11:07 远启 阅读(97) 评论(0) 推荐(0) 编辑
摘要:select CONCAT(ROUND(a/b*100,2),"%") from testnum; 阅读全文
posted @ 2021-09-23 18:50 远启 阅读(356) 评论(0) 推荐(0) 编辑
摘要:事务传播机制 阅读全文
posted @ 2021-07-28 15:20 远启 阅读(2409) 评论(0) 推荐(0) 编辑
摘要:mysql遍历查询结果,并操作 -- 创建存储过程之前需判断该存储过程是否已存在,若存在则删除 DROP PROCEDURE IF EXISTS fix_role_menu; -- 创建存储过程 CREATE PROCEDURE fix_role_menu() BEGIN -- 定义变量 DECLA 阅读全文
posted @ 2021-07-19 16:35 远启 阅读(2336) 评论(0) 推荐(0) 编辑
摘要:由于咱们是东8区,返回的是 1970-01-01 08:00:00 所以需要减去 8 小时 select date_format(date_sub(from_unixtime(288), INTERVAL 8 HOUR), '%H:%i:%s') from dual; 来个支持天的,计算为王 sel 阅读全文
posted @ 2021-06-05 17:44 远启 阅读(1448) 评论(0) 推荐(0) 编辑
摘要:select table_name from information_schema.columns where table_schema = '库名' and column_name='字段名'; 阅读全文
posted @ 2020-08-03 10:39 远启 阅读(7390) 评论(0) 推荐(0) 编辑
摘要:一.加密数据库中的已经存在的数据 阅读全文
posted @ 2019-04-23 15:41 远启 阅读(6733) 评论(0) 推荐(1) 编辑
摘要:此篇适合有一定的mybatis使用经验的人阅读. 一.批量更新 为了提升操作数据的效率,第一想到的是做批量操作,直接上批量更新代码: 生成的sql语句 二.批量添加 批量添加在做大量数据插入到mysql时,效率相对单条遍历插入大大提高; 但是数据是基于数据库层面做的约束的话,在插入的数据中有一个数据 阅读全文
posted @ 2019-04-23 10:06 远启 阅读(11652) 评论(0) 推荐(1) 编辑
摘要:一.删除数据库中的重复数据, 只留一条 阅读全文
posted @ 2019-04-20 18:25 远启 阅读(2182) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示