mysql简单操作(二)

修改表中数据

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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值