目录
方式一:insert into +表名 values (值,值....)
一、crud(增删改查)
1.1、查询
概念:
查询数据是指从数据库中根据需求,使用不同的查询方式来获取不同的数据,是使用频率最高、最重要的操作
注:在MySQL中,当执行一条SQL语句后,系统会返回一个"Affected row"的消息,表示该操作影响了多少行数据,也就代表SQL语句执行成功。这个消息通常用于INSERT、UPDATE、DELETE等操作,告诉你在数据库中有多少行数据受到了影响。
语法:
排序:where先加查询条件 > group分组 >having 筛选>order排序> limit分页
#基本查询
select * from t_book;
#加条件
select * from t_book where id>10;
分组
#按类别分组 ,前面不能放*号了会报错 select booktype ,count(1) from t_book group by booktype;
筛选
#筛选(类别大于2) as num取个别名 select booktype ,count(1) as num from t_book group by booktype having num>2;
排序
升序:asc 降序:desc
#排序降序 select booktype ,count(1) as num from t_book group by booktype having num>2 order by num desc; #错误做法:排序放分组前面 select booktype ,count(1) as num from t_book order by num desc group by booktype having num>2 ;
报错:查询语句中存在语法错误
分页
#一页一条数据 select booktype ,count(1) as num from t_book group by booktype having num>2 order by num desc limit 1;
1.2、增加
概念:
使用INSERT 语句向数据库已有的表中插入一行或者多行元组数据。