MYSQL条件查询:

1.条件过滤

select * from kfm;

select * from 表名 where 字段=value; 

eg:select * from kfm where dept_no = 3;

select * from 表名 where 字段 BETWEEN value1 AND value2;

eg:select * from kfm where dept_no between 1 AND 3;

 select * from 表名 where 字段 IN(value1,value2,value3);

eg:select * from kfm where dept_no in (1,2,3);

select * from kfm where dept_no not in (2,3,5);   (即为:除了2,3,5以外其余的输出)

select * from 表名 where 条件1 AND 条件2;

 select * from 表名 where 条件1 OR 条件2;


2.算术运算:

select 字段1 + 字段2  from 表名;(可以对查询出的结果进行算术运算)

 

 updata 表名 SET 字段=字段+value where 条件;(修改时也可进行算数运算)


3.NULL值查询:

#NULL值无法通过等值操作查询

#NULL值指的是未填值,注意跟空字符串做区分

select * from 表名 where 字段 IS NULL;

select * from 表名 where 字段 IS NOT NULL;


4.模糊查询:

LIKE 模糊查询 _表示一个任意字符    %表示零个或多个任意字符

select * from 表名 where 字段 like 'x_';

select * from 表名 where 字段 like 'x%';

select * from 表名 where 字段 like '%x%';

select * from 表名 where 字段 like '_x%';

Eg:


5.逻辑运算:

select * from 表名 where 字段 > value;  (where条件语句里开源写> < = != 等)


 6.排序:

ORDER BY 对结果集排序;DESC降序;ASC升序(默认);

select * from 表名 order by 字段1 desc,字段2 asc;


7.分页查询:

LIMIT对结果集分页;参数1:起始行;参数2:显示条数;

页码n   页大小s   LIMIT(n-1)*s,s

select * from 表名 limit 0,2;   (即为从第0行开始 显示两条数据)


8.单行函数:

length:计算长度

select length(‘123’);

select length(字段)from 表;

upper/lower:大小写转换

select upper('a') , lower('A');

select upper(字段),lower(字段) from 表;

concat:字符串拼接

select concat(upper('adc'),'def');  (结果为:ABCdef)

select concat(字段1,字段2)from 表;

eg: 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值