当前位置:网站首页>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对字段进行去重
字段前加
边栏推荐
猜你喜欢

DingTalk Enterprise Internal-H5 Micro Application Development

UR3机器人运动学分析之正运动学分析

ES6-模块

DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use

Chemical Reagent Phospholipid-Polyethylene Glycol-Amino, DSPE-PEG-amine, CAS: 474922-26-4

Image binarization processing of opencv

Pytorch study notes 10 - detailed explanation of convolutional neural network and application of multi-classification task of mnist dataset

crontab timing operation

变更管理与 DevOps —— 二者同时进行吗?

Unity转微信小游戏与JS交互
随机推荐
面试总爱问的一个问题,你为什么离职上一份工作?
Learning and understanding of ROS service programming
ES6-Map和Set
这些数组技巧,我爱了
C语言结构体(必须掌握版)
Picture-in-Picture API in the browser
The solution to the IDEA console not being able to enter information
安装显卡过程中遇到问题汇总
通过js禁止ctrl+滚轮放缩浏览器页面,禁止用手势放大
911崩了,自养号测评环境IP有哪些更好的选择
Solution for MySQL The table is full
Image binarization processing of opencv
file和stat命令的使用,文件类型:代表字符,以及英文
【Rhapsody学习笔记】4:Relations
ImportError: cannot import name 'Xxxx' from partially initialized module 'xx.xx.xx'
力扣151. 颠倒字符串中的单词
Pytorch study notes 13 - Basic_RNN
Webrtc从理论到实践三:角色
Unity转微信小游戏与JS交互
Use usb_cam to open multiple cameras at the same time