mysql(3) 查询

来源:互联网 发布:php print r 编辑:程序博客网 时间:2024/06/08 01:58

CURD占到数据库操作的80%

查询占到CURD的80%

查询时,列是变量,变量是可以计算的,where是表达式,查询时判断真假。

select uid from tp_user where 1;  1一直是真,所以会查找出整张表中的uid

select uid from tp_user where 0; 0是假,所以提示empty set.

select uid*2 from tp_user;

select username from tp_user;投影运算,即取出某一列或某几列

select uid,sex,uid-sex from tp_user;广义投影,列之间参与运算


select username from tp_user where uid != 2;  不等于

     >2;

  <=2; 

                     uid in (4,11);或者uid=4,或者uid=11

uid =4 or uid=11;

uid=4 || uid=11;

    uid between 4 and 11;在4~11之间

uid >=4 and uid <=11;

uid >=4 && uid <=11;

not   ! 逻辑非

or    || 逻辑或

and  && 逻辑与

and 的优先级高于or 要用括号提高优先级

like 模糊查询

% 通配任意字符

_  通配单一字符

where  goods_name like ‘诺基亚%’;  查找诺基亚开头的

where goods_name like '诺基亚___';  查找诺基亚开头的后面跟3个字符的东西

ps:查出来的是乱码:告诉服务器你是什么编码  set names gbk;


把uid是20-30之间的值设为20

update tp_user  set age=floor(age/10)*10 where age between 20 and 30;





0 0