Mysql学习-基础笔记

来源:互联网 发布:人工智能开发语言 编辑:程序博客网 时间:2024/05/22 03:54

3.

连接use DataBaseName打开show databaseshow tablesshow TableName还有其他show p19

4.

select:select namefrom tableName; select name1,name2from tableName;select *from tableName;distinct:(去重)select distinct idfrom products;limit:限制结果select id from productslimit 5;输出不超过5行select idfrom productslimit 3,4;从3行开始 输出不超过4行  或者 4 offset 3完全限定名database.tabletable.column

5.

排序:默认asc升序  desc 降序select *from productsorder by id;select *from productsorder by id desc;select *from productsorder by id desc,name;

6.

where :=<> 不等于!= 不等于<><=>=between  and  两个之间select *from productswhere name = 'asd' and id >=100 and id !=101and price between 1 and 2;空值检查  is null select *from productswhere price is null;

7.

数据过滤and or :select *from productswhere name = 'asd' and id >100;select *from productswhere id >=100 or id = 1;in: 在范围内select *from productswhere id in(1,2,3);not: 不在范围内select *from productswhere id not in(1,2,3);

8.

通配符 %   匹配任何字符出现次数select *from productswhere name like 'asd%';like '%asd'like 'a%d'like '%asd%'不能匹配空  like '%'通配符 _   匹配单个字符出现1次数 次数不能多也不能少  select *from productswhere name like 'asd_';

9.

正则表达式  :regexpselect *from productswhere name regexp '1000';  .   匹配任意一个字符  '.000'   or  匹配两个字符串  '1000 or 2000 '  []  匹配几个字符之一   '[123]'  '[0-9]' '[a-z]'  [^] 否定几个字符   '[^123]'   '[^0-9]'  '[^a-z]'   //  匹配特殊字符转义使用  '\\.'  '\\-'  匹配(.)(-) 字符   匹配字符类(    [:alnum:]   //任意字母和数字    [:alpha:]   //任意字符    [:blank:]   //空格和制表    [:cntrl:]   //ASCII控制符    [:digit:]   //任意数字    [:graph:]   //和[:print:]相同 不包括空格    [:lower:]   //小写字母    [:print:]   //任意可打印字符    [:punct:]   //既不在[:alnum:] 又不在[:cntrl:] 中的任意字符    [:space:]   //包括空格在内的任意空白字符    [:upper:]   //任意大写字母    [:xdigit:]  //任意十六进制数字  )     重复元字符(    *   0-N 个匹配    +   1-N 个匹配 {1,}    ?   0-1 个匹配 {01}    {n} 指定数目的匹配    {n,}    不少于指定数目的匹配    {n,m}   匹配数目的范围  m不超过255  )  定位符(    ^   文本开始    $  文本结尾    [[:<:]] 词的开始    [[:>:]] 词的结尾  )

10.

拼接字段 concatenateselect concat(name,' (',id,')')from vendorstrim函数: trim()  ltrim()   rtrim()  去掉串左右空格  去掉串左空格  去掉串右空格别名 as   concat() as total执行算术计算 + - * /  select id * pricefrom vendors

11.

文本处理函数left()  返回串左边字符right() 返回串右边字符length()返回串长度locate()找出串的一个子串ltrim() 去掉串左空格rtrim()去掉串右空格trim()去掉串左右空格lower()将串小写upper()将串大写soundex()返回串的soundexsubstring()返回子串的字符日期和时间处理函数  TODO-------------------------数值处理函数  TODO-------------------------

12.

聚集函数avg()   忽略值为null的行min()   忽略值为null的行max()   忽略值为null的行count()   count(*)nulll行也算上  count(column)忽略nullsum()   忽略值为null的行聚集不同值对所有值 all不同值  distinct

13.

group byhaving

14.

15.

16.

join onleft join onright join on

17.

unionunion all

18.

myisam  引擎 支持 全文本搜索 不支持事物管理  主键索引存储地址innodb  不支持文本搜索  支持事务管理 主键索引聚集建树

19.

insert into insert LOW_PRIORITY into 降低 insert into语句优先级

20.

update tablesetwheredelete from tablewheretruncate table  重建表

21.

建表 相关create table(    name  char not null)更新alter table vendorsadd vend_phone char;删除drop table  vendors;重命名rename table customers2 to customers;

22.

未完待续…