查询一张表:
select * from 表名;
查询指定字段:
select 字段1,字段2,字段3….from 表名;
where条件查询:
select 字段1,字段2,字段3 frome 表名 where 条件表达式;
例:select * from t_studect where id=1;
select * from t_student where age>22;
带in关键字查询:
select 字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);
例:select * from t_student where age in ('21','23');
select * from t_student where age not in ('21','23');
带between and的范围查询:
select 字段1,字段2 frome 表名 where 字段 [not]between 取值1 and 取值2;
例:select * from t_student where age between 21 and 29;
select * from t_student where age not between 21 and 29;
带like的模糊查询:
select 字段1,字段2… frome 表名 where 字段 [not] like ‘字符串’;
“%”代表任意字符;
“_”代表单个字符;
例:select * from t_student where stuName like ‘张三”;
select * from t_student where stuName like ‘张三%”;
select * from t_student where stuName like ‘%张三%”;//含有张三的任意字符
select * from t_student where stuName like ‘张三_”
空值查询:
select 字段1,字段2… from 表名 where 字段 is[not] null;
带and的多条件查询:
select 字段1,字段2…from 表名 where 条件表达式1 and 条件表达式2 [and 条件表达式n]
例:select * frome t_student where gradeName=’一年级’ and age=23
带or的多条件查询:
select 字段1,字段2…from 表名 where 条件表达式1 or 条件表达式2 [or 条件表达式n]
例:select * frome t_student where gradeName=’一年级’ or age=23;//或者,条件只要满足一个
distinct去重复查询:
select distinct 字段名 from 表名;
对查询结果排序order by:
select 字段1,字段2…from 表名 order by 属性名 [asc|desc]
例:select * from t_student order by age desc;//降序,从大到小
select * from t_student order by age asc;//升序,asc默认可以不写
内联表查询inner join:
select
字段1,字段2,字段3...
from
表1 inner join 表2 on 表1.字段 = 表2.字段
例:select
order_id,buyer_name,purchase_date,inland_name,inland_info,logistics_channel_code,freeze_amount,deduct_amount
from
by_mws_order inner join by_order_logistics on by_mws_order.id = by_order_logistics.oid
查询最近七点的数据
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)
查询用户授权权限
SHOW GRANTS FOR developers;
授予用户权限
GRANT lock tables ON 库名.* TO '用户'@'%';
删除用户权限
REVOKE 权限 ON *.* FROM '用户'@'%';
