摘要: /* Windows服务 */ -- 启动MySQL net start mysql -- 创建Windows服务 sc create mysql binPath= mysqld_bin_path(注意:等号与值之间有空格) /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用 阅读全文
posted @ 2025-04-09 00:15 程序员の奇妙冒险 阅读(49) 评论(0) 推荐(0)
摘要: 索引的本质 索引是帮助mysql高效获取数据的排好序的数据结构 索引存储在文件里 索引结构 二叉树(红黑树:二叉平衡树) hash BTREE B-Tree与B+Tree B+Tree是B-Tree的变种 B-Tree 度-节点的数据存储个数 叶节点具有相同的深度 叶节点的指针为空 节点中的数据ke 阅读全文
posted @ 2025-04-09 00:14 程序员の奇妙冒险 阅读(92) 评论(0) 推荐(0)
摘要: 读未提交(Read uncommitted) 读提交(read committed) 可重复读(repeatable read) 串行化(Serializable) 读未提交(RU): 一个事务还没提交时, 它做的变更就能被别的事务看到.【可以看到未提交的数据(脏读)】 读提交(RC): 一个事务提 阅读全文
posted @ 2025-04-09 00:12 程序员の奇妙冒险 阅读(50) 评论(0) 推荐(0)
摘要: mysql 配置 [mysqld] lower_case_table_names=1 # 添加此行代码重启mysql即可 阅读全文
posted @ 2025-04-09 00:09 程序员の奇妙冒险 阅读(20) 评论(0) 推荐(0)
摘要: - 查询30天 select DATE_SUB(CURDATE(), INTERVAL 30 DAY) frm table; 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE DA 阅读全文
posted @ 2025-04-09 00:00 程序员の奇妙冒险 阅读(115) 评论(0) 推荐(0)
摘要: SELECT * FROM your_table WHERE date_column >= CURDATE() - INTERVAL 30 DAY 阅读全文
posted @ 2025-04-08 23:59 程序员の奇妙冒险 阅读(28) 评论(0) 推荐(0)
摘要: SELECT object_id, SUM(CASE WHEN date_column >= CURDATE() - INTERVAL 30 DAY AND date_column < CURDATE() THEN amount ELSE 0 END) AS amount_30_days, SUM( 阅读全文
posted @ 2025-04-08 23:59 程序员の奇妙冒险 阅读(42) 评论(0) 推荐(0)
摘要: /*获取指定id的上一条记录,我这里是以id=5为例的*/ select cid,cname from company order by cid>=5,cid desc limit 1 /*获取指定id的下一条记录,我这里是以id=5为例的*/ SELECT cid,cname from compa 阅读全文
posted @ 2025-04-08 23:58 程序员の奇妙冒险 阅读(120) 评论(0) 推荐(0)
摘要: SELECT * FROM tb_product WHERE create_date BETWEEN STR_TO_DATE( date_format( CURRENT_DATE (), '%Y-%m-01 00:00:00' ), '%Y-%m-%d %H:%i:%s' ) AND STR_TO_ 阅读全文
posted @ 2025-04-08 23:58 程序员の奇妙冒险 阅读(23) 评论(0) 推荐(0)
摘要: 创建表 Create table If Not Exists Scores (Id int, Score DECIMAL(3,2)); insert into Scores (Id, Score) values ('1', '3.5'); insert into Scores (Id, Score) 阅读全文
posted @ 2025-04-08 23:57 程序员の奇妙冒险 阅读(61) 评论(0) 推荐(0)
摘要: SELECT * FROM sys_menu WHERE id in ( select id from ( select t1.id, if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischi 阅读全文
posted @ 2025-04-08 23:56 程序员の奇妙冒险 阅读(70) 评论(0) 推荐(0)
摘要: 分类递归查询子节点 delimiter $$ drop function if exists get_child_categoryt$$ create function get_child_categoryt(in_id varchar(10)) returns varchar(1000) begi 阅读全文
posted @ 2025-04-08 23:55 程序员の奇妙冒险 阅读(75) 评论(0) 推荐(0)
摘要: //status = 0 为未支付状态 select * FROM order WHERE TIMESTAMPDIFF(MINUTE,create_date,now()) > 20 AND status = 0; 阅读全文
posted @ 2025-04-08 23:52 程序员の奇妙冒险 阅读(39) 评论(0) 推荐(0)
摘要: -- 返回的是某月某日的数量 SELECT monthDay, count( 0 ) AS numb FROM ( SELECT -- 返回的是月日 date_format( create_date, '%m-%d' ) monthDay FROM tb_product WHERE create_d 阅读全文
posted @ 2025-04-08 23:52 程序员の奇妙冒险 阅读(42) 评论(0) 推荐(0)
摘要: Logins table: + + + | user_id | login_date | + + + | 1 | 2019-07-20 | | 1 | 2019-07-20 | | 1 | 2019-07-20 | | 2 | 2019-07-20 | | 2 | 2019-07-21 | | 2 阅读全文
posted @ 2025-04-08 23:51 程序员の奇妙冒险 阅读(26) 评论(0) 推荐(0)
摘要: 近 30天的每日活跃用户数(当天只要有一条活动记录,即为活跃用户)。 Activity table: + + + + + | user_id | session_id | activity_date | activity_type | + + + + + | 1 | 1 | 2019-07-20 | 阅读全文
posted @ 2025-04-08 23:50 程序员の奇妙冒险 阅读(78) 评论(0) 推荐(0)
摘要: 这种查询会导致全表扫描 select id,name,create_date from sys_user a where not exists (select * from sys_user b where a.name = b.name and a.create_date < create_dat 阅读全文
posted @ 2025-04-08 23:49 程序员の奇妙冒险 阅读(30) 评论(0) 推荐(0)
摘要: drop procedure if exists init_group_val; delimiter $ create PROCEDURE init_group_val() BEGIN DECLARE group_id VARCHAR(64); -- 遍历数据结束标志 DECLARE done IN 阅读全文
posted @ 2025-04-08 23:46 程序员の奇妙冒险 阅读(38) 评论(0) 推荐(0)
摘要: select a.id,substring_index(substring_index(a.val,',',b.help_topic_id+1),',',-1) from tbl_brand_attr_group a join mysql.help_topic b on b.help_topic_i 阅读全文
posted @ 2025-04-08 23:43 程序员の奇妙冒险 阅读(44) 评论(0) 推荐(0)
摘要: delimiter $ create PROCEDURE phoneDeal() BEGIN DECLARE ids varchar(64); -- 遍历数据结束标志 DECLARE done INT DEFAULT FALSE; -- 游标 DECLARE cur_account CURSOR F 阅读全文
posted @ 2025-04-08 23:42 程序员の奇妙冒险 阅读(16) 评论(0) 推荐(0)