修改表中数据
UPDATE people set name='阿二' where id=123456798;
删除表中数据
DELETE FROM people where id=111;
修改和删除如果不加where是修改或删除所有数据。
(DQL)
一、单表查询:
查people表里所有数据:
select * from people
查people表里人名和年纪;
select name ,age from people;
不重复查询年纪
select DISTINCT age from people;
查询年纪为10的人和他所有信息
select * from people where age='10';
查找年纪不在10和18岁的人
select * from people where age not in('10','18');
查以id是89结尾的人
select * from people where id like '%89';
98%是以98开头,%98%含有98就可以。
双条件:
select * from people where id like '%89' or age='10';
and都符合,or符合其一。
id降序排序:
select * from people ORDER BY id desc;
性别升序,id降序
select * from people ORDER BY gender asc, id desc;
表中一共几行数据
select count(*) from people;
性别去重后,表中一共几行数据
select count(DISTINCT gender) from people;
查询表中一共几行数据,并按年纪分组
select count(*) from people GROUP BY age;
以上条件+打印出年纪
select count(*),age from people GROUP BY age;
只统计age为10的数据一共有几条
select count(*) from people GROUP BY age having age='10';
只查询表前三行数据:
select * from people limit 3
分页查询,前三行数据一页:
select * from people limit 0,3;
后三行一页:
select * from people limit 3,3;