MYSQL DML增删改 命令

插入一条记录

 insert into users(uid,uname,upassword) values(null,'me','123');

查询一条记录

select * from users

更新全部字段

UPDATE users SET upassword='666';

带条件更新

UPDATE users SET upassword='999' WHERE uid=1;

带条件删除

DELETE FROM users WHERE uid=1 

全部删除

DELETE FROM users;

查询所有表

select * from product; 表名

查询 pname price字段

select pname,price from product;

查询字段 去除重复

 select distinct(price) from product;

查询商品为qwe的字段

select * from product where pname='qwe';

查询price大于50的字段

select * from product where price > 50;

大于等于

select * from product where price >= 998;

查询含有q的字段

select * from product where pname like '%q%';

查询id 4 5 6 字段

select * from product where pid in(4,5,6);

查询 2 5 id

select * from product where pid=2 or pid=5;

查询排序 按照价格从小到大

 select * from product order by price asc;

按照时间从大到小

select * from product order by pdate desc;

聚合函数

获得所有商品的价格的总和

select sum(price) from product;

平均价格

 select  avg(price) from  product;

获取所有商品个数

 select count(*) from product;
4.5 分组操作

1.添加分类id

alter table product add cid varchar(32);

2.初始化数据

update product set cid='1';
update product set cid='2' where  pid in (5,6,7);

根据cid字段分组,分组后统计商品的个数

 select cid ,count(*) from product group by cid;

根据cid查询每组的大于0的平均价格

select cid,avg(price) from product group by cid having avg(price) > 0;

select  一般在的后面的内容都是要查询的字段

from  要查询到表

where

group by

having  分组后带有条件只能使用having

order by 它必须放到最后面

转载于:https://my.oschina.net/u/2999760/blog/1486438

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值