插入語句
insert into 表名(表的字段1,表的字段2)values(字段1的值,字段2的值);字符串類型的加上引號
例如:insert into menu
(id
,menuname
,price
,img
)value(NULL,'牛肉羹','20','https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2759220099,553595254&fm=27&gp=0.jpg');
刪除語句
delete from 表名 where name
=luxp
;
delect from student where name="luxp";
修改語句
update 表名 set 字段1=‘值’,字段2=‘值’ where 條件//update student set age=18 where name='luxp';
如:update student set name='li',age=15,where name='luxp';
查詢語句
我們用的最多的而且最重要的就是查詢語句
- select 字段1,字段2....from 表名 where 條件
- SELECT * FROM student limit 1,2
limit 1代表只查詢記錄中的一條
limit 5代表查詢記錄中的5條
limit start,size 從start位置開始查詢size條
帶查詢條件的查詢語句
select 字段 from 表名 where 條件 limit start ,size; - 排序 order by
desc根據(jù)字段的值降序
默認(rèn)的是asc升序
select * from student where city="北京" order by asc limit 1,2; - 分組統(tǒng)計(jì)查詢
select count()from 表名 //獲得所有的行數(shù)
select count() as num from 表名 //將count接口作為一個(gè)字段名檢索
分組group by 字段名 根據(jù)某個(gè)字段進(jìn)行分組查詢
select city,count(*) as num from student group by city - 索引可以提供查詢速度,可以降低插入,修改速度
- 求和 sum()
select sum(age) as num from student where 1; - 求平均值avg()
select avg(age) from student;//求年齡的平均值 - 查最大值和最小值max(age)min(age);
select max(age),min(age) from student;