当前位置:网站首页>MySQL表的增删改查(1)
MySQL表的增删改查(1)
2022-07-31 05:19:00 【欧粒粒】
增查更删(CRUD)
一、插入数据
1.全列插入,表示所有字段都要插入值,并且插入的顺序是表定义时候的顺序。
(浮点型,整形注意不能超出定义的长度范围)
-- 全列插入
insert into 表名 values(字段1要插入的值,字段2要插入的值);2.指定列插入
insert into 表名(要插入的字段1,要插入的字段2)values(要插入的值1,要插入的值2);只插入我们需要的字段,其他没有插入的字段是空(null)。
3.插入多行数据
(1)执行多条insert语句
(2)执行一条:
insert into 表名(id,username)values
(1,'烤鸭'),
(2,'进京赶考');二、查询
1.全列查询
select * from 表名;
查询该表所有字段,所有数据
select * from student;
2.指定列查询
select 查询列1,查询列2 from 表名;
查询给定的字段
select id, username from student;3.如果字段是数值型,可以使用运算符计算
select id, username, amount*2 from student;补充:
字符串:MySQL中,字符串拼接,不能使用+,需要使用一个concat(str1,str2,str3....)函数
select id,concat(username,'学生') from student;表或者字段 别名:如果查询字段,进行了计算等操作,查询返回的字段,就不是数据库定义的字段名。此时,一般,会自动使用别名。
(1)字段别名
--amount*2作为查询字段名,不好看,一般会使用别名。用空格加别名或者as加别名
select id i, username as u, amount*2 a from student;别名最终会作为查询结果集(虚拟表)的字段名。
(2)表别名
--表名也可以使用别名。也是加上空格或者as,但需要注意要给字段加上表别名和.
select stu.id i, stu.username as u, stu.amount*2 a from student stu;4.日期的操作
--日期的操作:也需要使用函数
--year(日期的值),month(日期的值),day(日期的值)
select id, username, year(birthday), month(birthday), day(birthday) from student;5.distinct对字段进行去重
字段前加
边栏推荐
- C语言对文件的操作(完整版)
- 螺旋矩阵Ⅱ
- Remote file xxx is mapped to the local path xxx and can't be found. You can continue debugging....
- windows下mysql忘记密码登录,并创建用户
- 滴滴被罚超80亿!收集并泄露1.07亿条乘客人脸识别信息
- 超详细!!!让你了解冒泡排序的底层逻辑和思想
- ROS subscription to multiple topics time synchronization problem
- C语言知识点(二)
- 通过js禁止ctrl+滚轮放缩浏览器页面,禁止用手势放大
- 变更管理与 DevOps —— 二者同时进行吗?
猜你喜欢

Picture-in-Picture API in the browser

在 AWS 上从零开始设置 Incredibuild 构建系统

file和stat命令的使用,文件类型:代表字符,以及英文

概率论相关笔记

TCP与UDP协议的区别,以及TCP的三次握手和四次挥手

UE5 最新动态虚幻引擎全新版本引爆互联网

Log jar package conflict, and its solution

DingTalk Enterprise Internal-H5 Micro Application Development

DOM操作案例1-点击,使表格的颜色切换(点击单元格,整行或整列颜色切换)

小型网站组建(ENSP)
随机推荐
Pytorch learning notes 09 - multiple classification problem
ES6-Map、Set与Arrary的转换
Webrtc从理论到实践二: 架构
ES6-模块
ImportError: cannot import name ‘Xxxx‘ from partially initialized module ‘xx.xx.xx‘
关于网络安全法的个人理解
Wlan实验(ENSP)
Webrtc从理论到实践三:角色
【Rhapsody学习笔记】3:Dishwasher
Remote file xxx is mapped to the local path xxx and can't be found. You can continue debugging....
螺旋矩阵Ⅱ
这些数组技巧,我爱了
UR3机器人雅克比矩阵
ES6-Map和Set
UE5 最新动态虚幻引擎全新版本引爆互联网
小型网站组建(ENSP)
MySQL free installation download and configuration tutorial
力扣.三数之和/四数之和
【Rhapsody学习笔记】1:Hello World
2022年软件测试现状最新报告