MySql增删改查(基础)

1.插入记录

insert into() values();  按照列插入值
例:insert into table(pname,price) values('mac',20000);
insert intovalues// 插入所有的列
例:insert into table values(null,'苹果电脑',20000);

2.更新记录

updateset=,=where条件
例
update product 

3.删除记录

delet fromwhere  条件
例:delete from producr where price =20000;

4.查询记录[重点]

1.select * from2.查询商品表里面的所有的列
select * from product;

3.查询商品名字和价格
select name,price from product;

4.去重查询商品的价格
select distinct price from product ;

5.取出表中的每条数据,满足条件的记录就返回,不满足条件的记录不返回
select ... fromwhere pid in(1,2,3,4)

6.between...and...  区间查询
select * from product where price between 1000 and 2000   相当于1000<=price<=3000

7.like 模糊查询    一般和_或者%一起使用

- _ 占一位
- %0或者n位

select * from table where name like '张%'

8.and  多条件同时满足
where 条件1 and 条件2 and 条件3

9.任意条件满足
where 条件1 or 条件2 or 条件3


5.排序查询

1.语法:  只按某一个字段进行排序,单列排序
select ... from 表明 where 条件 order by 字段名[asc|desc]  asc:升序,desc:降序,不指定默认升序

2.练习: 以分数降序查询所有的学生
select * from student order by score desc



6.聚合函数

1.最大值 max(列名)
select max(score) from student
2.最小值 min(列名)

3.平均值 avg(列名)

4.求和 sum(列名)

7.分页查询

1.select ... from .... limit 起始行数,查询的记录条数.
limit a,b

a 起始行 
b 返回的行数

例:每页查询4个
第一页 a=0,b=4
第二页 a=4,b=4
第三页 a=8,b=4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值