随笔分类 -  Mysql

摘要:在mysql 8 使用 CTE递归查询时,出现了这个报错 WITH recursive area AS ( SELECT area_name, area_code FROM sys_area_tree WHERE area_category = '1' AND parent_code IS NULL 阅读全文
posted @ 2023-10-23 14:00 唏嘘- 阅读(406) 评论(0) 推荐(0) 编辑
摘要:表数据: 期望数据: 实现sql: select a.id, b.help_topic_id +1, a.execute_name, #substring_index(a.execute_name,',',b.help_topic_id+1), substring_index(substring_i 阅读全文
posted @ 2023-09-13 14:09 唏嘘- 阅读(737) 评论(0) 推荐(0) 编辑
摘要:UTF-8 编码是一种变长的编码机制,可以用1~4个字节存储字符。 MySQL 中的 utf8 编码并不是真正的 UTF-8,其最长只有3个字节。当遇到占4个字节的 UTF-8 编码,例如 emoji 字符或者复杂的汉字,会导致存储异常。 从 5.5.3 开始,MySQL 开始用 utf8mb4 编 阅读全文
posted @ 2023-05-29 16:57 唏嘘- 阅读(458) 评论(0) 推荐(0) 编辑
摘要:一:CONCAT(string1,string2,...) 此方法可拼接多个值,如果存在一个为 【null】,则结果返回为【null】 二:CONCAT_WS(separator,string1,string2,...) 可以多个字符串用指定的字符串进行拼接,string1,string2代表的是字 阅读全文
posted @ 2023-05-29 16:32 唏嘘- 阅读(2341) 评论(0) 推荐(0) 编辑
摘要:MySQL从8.0版本开始支持窗口函数。 窗口函数的作用类似于在查询中对数据进行分组,不同的是,分组操作会把分组的结果聚合成一条记录,而窗口函数是将分组的结果置于每一条数据记录中。 窗口函数总体上可以分为序号函数, 分布函数, 前后函数, 首尾函数和其他函数; 语法结构: 窗口函数的语法结构: (1 阅读全文
posted @ 2023-05-19 14:32 唏嘘- 阅读(79) 评论(0) 推荐(0) 编辑
摘要:1、将手机号码中间四位隐藏 select REPLACE(mobile, SUBSTR(mobile,4,4), '****') from users 2、将手机号码中间四位隐藏(推荐使用) select insert(mobile, 4, 4, '****') from users ; 参考:ht 阅读全文
posted @ 2023-01-13 09:28 唏嘘- 阅读(758) 评论(0) 推荐(0) 编辑
摘要:报错提示: > 1292 - Truncated incorrect DOUBLE value: '1,' 原因: update device set type = REPLACE(type, '2', '') where type = 2; type 类型为varchar,需要改为 update 阅读全文
posted @ 2022-12-08 15:59 唏嘘- 阅读(482) 评论(0) 推荐(0) 编辑
摘要:1、如果只有一个字段数据重复 自关联,保留id最小的那一条,其它的都删除 DELETE t1 FROM user t1, user t2 WHERE t1.user_code = t2.user_code AND t1.id > t2.id; 2、如果是全部字段都相同 delete from use 阅读全文
posted @ 2022-07-01 09:51 唏嘘- 阅读(1064) 评论(0) 推荐(0) 编辑
摘要:1093 - You can't specify target table 'table_name' for update in FROM clause;不能先select出同一表中的某些值,再update这个表(在同一语句中) 原语句: delete from i_user where b_cod 阅读全文
posted @ 2022-07-01 09:34 唏嘘- 阅读(31) 评论(0) 推荐(0) 编辑
摘要:select DISTINCT(left(created_on, 10)) createDate from record where plan_id = '123456789' order by created_on desc; 报错信息: Expression #1 of ORDER BY cla 阅读全文
posted @ 2022-06-23 15:27 唏嘘- 阅读(568) 评论(0) 推荐(0) 编辑
摘要:MySQL中char_length(str),length(str)都属于判断长度的内置函数,根据其得到字符串的长度; char_length(str) 计算单位:字符 不管汉字还是数字或者是字母都算是一个字符 length(str) 计算单位:字节 utf8编码:一个汉字三个字节,一个数字或字母一 阅读全文
posted @ 2022-06-20 10:56 唏嘘- 阅读(11413) 评论(0) 推荐(0) 编辑
摘要:1. not in的结果集中出现null则查询结果为null; select * from device where code not in ('A', 'B', null); 上面查询结果为 null,查不出想要的结果 2、in的结果集中出现null不影响; select * from devic 阅读全文
posted @ 2022-06-13 17:03 唏嘘- 阅读(295) 评论(0) 推荐(0) 编辑
摘要:人员按照中文首字母排序 sql: select * from staff ORDER BY CONVERT(`name` USING gbk) mybatis-plus: orderByAsc("convert(" + name + " using gbk)") 阅读全文
posted @ 2022-02-11 16:19 唏嘘- 阅读(131) 评论(0) 推荐(0) 编辑
摘要:1、Windows 下 启动服务: net start mysql 关闭服务: net stop mysql 2、Linux下 启动服务: service mysql start 关闭服务: service mysql stop 阅读全文
posted @ 2021-12-19 11:23 唏嘘- 阅读(75) 评论(0) 推荐(0) 编辑
摘要:报错信息: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in 阅读全文
posted @ 2021-09-17 11:35 唏嘘- 阅读(96) 评论(0) 推荐(1) 编辑
摘要:开启了bin-log, 我们就必须指定我们的函数是否是: 1 DETERMINISTIC 确定性的 2 NO SQL 没有SQl语句,当然也不会修改数据 3 READS SQL DATA 只是读取数据,当然也不会修改数据 4 MODIFIES SQL DATA 要修改数据 5 CONTAINS SQ 阅读全文
posted @ 2021-09-16 20:37 唏嘘- 阅读(1301) 评论(0) 推荐(0) 编辑
摘要:默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。 1、修改/etc/mysql/my.conf 找到bind-address = 127.0.0.1这一行改为bind-address = 0.0.0.0即可 2、为需要远程登录的用户赋予权 阅读全文
posted @ 2021-09-07 17:53 唏嘘- 阅读(1286) 评论(0) 推荐(0) 编辑
摘要:错误原因: 使用Navicat Premium 12连接MySQL数据库时会出现Authentication plugin 'caching_sha2_password' cannot be loaded的错误。 mysql8 之前的版本中加密规则是mysql_native_password,而在m 阅读全文
posted @ 2021-09-07 17:45 唏嘘- 阅读(143) 评论(0) 推荐(0) 编辑
摘要:一:导出视图 SELECT CONCAT("DROP VIEW IF EXISTS `",TABLE_SCHEMA,"`.`",TABLE_NAME,"`;\nCREATE VIEW `", TABLE_SCHEMA,"`.`",TABLE_NAME,"` as ",VIEW_DEFINITION, 阅读全文
posted @ 2021-09-02 17:35 唏嘘- 阅读(882) 评论(0) 推荐(0) 编辑
摘要:一、创建视图: CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] 阅读全文
posted @ 2021-09-02 15:17 唏嘘- 阅读(74) 评论(0) 推荐(0) 编辑

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