数据库表操作补遗

来源:互联网 发布:淘宝卖五金没销量 编辑:程序博客网 时间:2024/06/05 07:07

单表查询:①所有字段:select  * from  表名

②指定字段:select  项,项   from  表名

③指定记录:select 项 from 表名where 所需查询一个已知项=项值;

离散型: in  :select  * from 表名 where  项  in(“项值”)/项=“项值”;

连续型:(between and ) =  >=   <= 等

        Select *  from 表名 where  项  between 项值1  and  项值2;(项值1.2是包含关系);

模式匹配:like    注:通配符:%(0个或多个) _(一个)

         Select *  from  表名 where  项  like “项值%”;

多条件:and/or  :select * from  表名where 项=项值  and  项=项值;

空值:null :select  * from  表名  where 项值  is null;

保存不重复:distinct:select  distinct 项 from 表名;

排序:order  by <asc/desc>:select  *  from表名 order  by  项  desc;

限定范围:limit(个数):select  * from 表名 order by 项 asc limit 个数;(limit 3:头三条;limit  1,2:第一个开始的两条);

分组与统计:count,sum,arg,min,max:select count(*),项 from 表名group by 其他项;

转义字符:‘\n’换行;‘\t’空格

Ascll:select ox41;   结果:A

      Select east(ox41  as  unisigned);  结果:65

      Select hex(‘Aa’);  结果:4161

      <hex转化字符为ascll值>

时间:date,time,datetime,timestamp

运算符:5=‘5ab’ 解释:正确,比较第一位

      Select bin(~1)  结果:63个1,一个0;

       Select 5>>2    结果:转化为二进制推移;

      4&5&6  转化为二进制与运算后转化为十进制

数学函数:abs()绝对值;sqrt():开根号;cell():返回比他大的最小整数;rand:随机数;round:四舍五入;power(2,3):2^3;exp(2):e^2;truncate(2.55,1) :2.5

字符函数:concat(‘bei’,‘jing’): beijing;concat_ws(‘-’,‘bei’,‘jing’):bei-jing  ;

原创粉丝点击