随笔分类 -  mysql

摘要:# 背景:person_info 表存放用户信息中有1千万数据,ID为主键,addr存放省份ID;addr_table表存放省份数据,有34条数据,ID为主键; # 统计所有地区的人员人数 select ad.name, count(pio.id) as pid from addr_table ad 阅读全文
posted @ 2024-12-14 16:27 萧一下 阅读(80) 评论(0) 推荐(0)
摘要:1、使用 随机数 当作主键ID的结果进行查询出现 没有 或者 多个 结果的情况 # 通过rand函数随机取一行数据select * from name_first where id = (floor(rand() * (select count(*) from name_first)) + 1);# 阅读全文
posted @ 2024-12-13 15:33 萧一下 阅读(37) 评论(0) 推荐(0)
摘要:# 创建一个表# 需求:id 为主键,并自增;name 不能为空,且不可重复;age 年龄在 0-120 之间;status 状态默认为 1,gender 性别要求 无create table person( id int primary key auto_increment comment '主键 阅读全文
posted @ 2024-11-29 15:22 萧一下 阅读(24) 评论(0) 推荐(0)
摘要:# 字符串函数 # 拼接两个字符串 concat(字符串1, 字符串2) select concat('123', '456'); # 123456 # 字符串中所有字符转小写 lower(字符串) select lower('Hello'); # hello # 字符串中所有字符转大写 upper 阅读全文
posted @ 2024-11-28 15:21 萧一下 阅读(25) 评论(0) 推荐(0)
摘要:1、数据库操作、表操作 # 显示所有数据库 show databases # 创建数据库:create database 数据库名 CREATE database study_mysql # 使用数据库 use study_mysql # 创建表:create table 表名() comment 阅读全文
posted @ 2024-11-26 16:47 萧一下 阅读(59) 评论(0) 推荐(0)