MySQL常用基础命令

1. 创建表

create table 表明
(
id number(11) primary key,
goodsid number(12) not null,
vendorid number(12),
batchid number(12),
userid number(10),
approvestatus number(2),
jobstatus number(2)
)

2. 添加字段

alter table table_name add 字段 类型;

3. 添加数据

方法一:INSERT INTO table_name (1,2,...) VALUES (1,2,....)
方法二:insert into table_name values(1,2,....)

4. 删除表

delete from table _name 

5. 修改字段值

UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

6. 查找单表

select * from table_name

7. 模糊查询含有小的

select * from table_name where 字段 like'%小%'

8. 多字段模糊查询(多用户首页查询)

SELECT * FROM goods WHERE CONCAT (IFNULL(goods_name,''),IFNULL(goods_describe,'')) LIKE '%神奇%'

9. 查询某个字段为空所有值

select * from table_name where 字段 is null

10. 查询出来有哪些重复的

select * from order_info group by user_id having count(user_id)>1;

11. 查询出来重复的数据

select count(1) from order_info WHERE user_id in ( select user_id from order_info group by user_id having count(user_id)>1)

12. 查询出来某个字段出现的次数

select id,count(*) from goods GROUP BY id having count(*)>0 

13. 查询出5条按照id出现次数倒叙

select id,count(*)as 'num' from goods GROUP BY id ORDER BY num desc LIMIT 0,5

14. 两表联合查询查询商品和商品详情

SELECT g.*,d.* FROM goods g,goods_dtl d
WHERE g.`id`=d.`goods_id`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XuDream

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值