当前位置:网站首页>mysql增删查改
mysql增删查改
2022-07-19 21:37:00 【盛夏洋光】
文章目录
1. 表内插入数据
已知表如图:
1.1 单行数据插入
blog.csdnimg.cn/14d8488f1cc44d52b555b1e2888f02e2.png)
在商品表中插入一条数据:名称为“学生书包”、价格18.91、库存101、描述为空
insert into goods values(‘学生书包’,18.91,101,null);
1.2 多行数据插入
insert into goods values(‘床’,500.99,200,null),(‘桌子’,200.99,100,null);
1.3 指定列插入
在商品表中插入一条数据:名称为“笔记本电脑”、价格6566.99.
insert into goods(name,price) values(‘笔记本电脑’,6566.99);
2. 查询表内数据
2.1 查询表内所有数据
select * from goods;
2.2 指定条件查询(where)
比较运算符:
运算符 | 说明 |
---|---|
>, >=, <, <= | 大于,大于等于,小于,小于等于 |
<=> | 等于,NULL 安全,例如 NULL <=> NULL 的结果是 TRUE(1) |
BETWEEN a0 AND a1 | 范围匹配,[a0, a1],如果 a0 <= value <= a1,返回 TRUE(1) |
LIKE | 模糊匹配。% 表示任意多个(包括 0 个)任意字符;_ 表示任意一个字符 |
逻辑运算符:
运算符 | 说明 |
---|---|
AND | 多个条件必须都为 TRUE(1),结果才是 TRUE(1 |
OR | 任意一个条件为 TRUE(1), 结果为 TRUE(1) |
NOT | 条件为 TRUE(1),结果为 FALSE(0) |
2AND的优先级高于OR,在同时使用时,需要使用小括号()包裹优先执行的部分
student学生表中,字段有姓名name,年龄age,要求查询姓张,并且年龄在18到25岁之间的学生
2.3 起别名查询
() as () 将前一个括号的表达式结果 用 后面括号名字表示
select id, name, chinese + math + english as 总分 from student;
2.4 去重查询(distinct)
去除学生数学成绩中的重复数据查询
select distinct math from student;
2.5 排序查询(order by)
– ASC 为升序(从小到大)
– DESC 为降序(从大到小)
select name, qq_mail from student order by qq_mail;(默认升序)
select name, qq_mail from student order by qq_mail DESC;(降序)
例子
查询article文章表中,文章标题title为空,或者满足发表日期create_date在2019年1月1日之后
select * from article where title is null or create_date > ‘2019-1-1 00:00:00’;
3 修改操作
update 表名 set
修改所有库存大于30的商品记录,将价格增加50块
update goods set price = price + 50 where stock > 30;
修改“Java核心技术”的图书信息,将价格修改为61
update book set price = 61 where name = ‘java核心技术’;
4. 删除操作
删除商品表中,价格大于60,或者是库存小于200的记录
delete from goods where price > 60 or stock < 200;
边栏推荐
- 微信小程序应用开发(一)
- 最大矩阵和 js
- Tsukuba University | reward prediction errors, rather than sensory prediction errors, play an important role in the model selection of human reinforcement learning
- uniapp使用Hbuilder X方式, 安装uivew插件步骤
- 华为无线设备漫游配置同一业务VLAN的AP间非快速漫游
- 散户炒股选哪个证券公司手续费低,手机上开户安全吗
- See Zhihu salt for free
- The most complete idea debug debugging skills in history (super detailed cases)
- Implementation of fruit and vegetable mall management system based on SSM
- 学生思维VS职场思维
猜你喜欢
连接无限·协同无界|融云首届全球企业通信云大会 WECC 来了
Summary of SQL skills in data warehouse development
【Matlab】解决使用Mex 报错There was a problem creating the mex file for Real Time Execution ,Please ensure y
How to do a good job in the design of test cases? The zero foundation of software testing must see
掌动智能国产性能测试工具XRunner正式亮相QECon
从wolai转移到Notion
【Go语言】(一)环境搭建与了解VScode工具
嵌套if选择结构与switch选择结构
Knowledge points of common interview questions: distributed lock
整流桥厂家ASEMI有哪些型号,整流桥厂家的电镀工艺怎么样?
随机推荐
The latest programming ranking in July: when can the top three, which have not changed for ten thousand years, be the first?
CPDA|先学数据分析工具还是数据分析思维?
Matlab 语法小问题 【问答随笔·4】
散户炒股选哪个证券公司手续费低,手机上开户安全吗
The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
优化冒泡排序
Debezium系列之:优化集群参数和支持debezium connector个性化设置
openharmony萌新贡献指南
How to publish and subscribe messages with redis? What is the implementation principle?
典型的数据湖应用案例
Day008 选择结构 (switch语句)
Explore the secret behind the improvement of music and painting quality. A thousand yuan gift is waiting for you
微信小程序应用开发(一)
The interviewer asked me why the GC generational collection algorithm of JVM was so designed
Deep decryption of go language context
Ott large screen "new audience rating system" is coming, and advertisers are no longer confused?
Es6-11 learning notes
SQL question brushing: find out the current salary of all employees
What is the difference between ASUS Tinker board 2S and raspberry pie 4B
Knowledge points of common interview questions: distributed lock