Mysql学习-基础笔记

3.

连接

use DataBaseName

打开

show database

show tables

show TableName


还有其他show p19

4.

select:

select name
from tableName; 

select name1,name2
from tableName;

select *
from tableName;



distinct:(去重)

select distinct id
from products;




limit:限制结果

select id 
from products
limit 5;输出不超过5行

select id
from products
limit 3,4;从3行开始 输出不超过4行  或者 4 offset 3


完全限定名

database.table
table.column

5.

排序:默认asc升序  desc 降序
select *
from products
order by id;

select *
from products
order by id desc;


select *
from products
order by id desc,name;

6.

where :

=
<> 不等于
!= 不等于
<
>
<=
>=
between  and  两个之间



select *
from products
where name = 'asd' 
and id >=100 
and id !=101
and price between 1 and 2;


空值检查  is null 

select *
from products
where price is null;

7.

数据过滤

and or :

select *
from products
where name = 'asd' and id >100;

select *
from products
where id >=100 or id = 1;


in: 在范围内
select *
from products
where id in(1,2,3);


not: 不在范围内

select *
from products
where id not in(1,2,3);

8.

通配符 %   匹配任何字符出现次数

select *
from products
where name like 'asd%';

like '%asd'
like 'a%d'
like '%asd%'

不能匹配空  like '%'


通配符 _   匹配单个字符出现1次数 次数不能多也不能少  

select *
from products
where name like 'asd_';

9.

正则表达式  :regexp

select *
from products
where 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.

拼接字段 concatenate

select concat(name,' (',id,')')
from vendors

trim函数: trim()  ltrim()   rtrim()  去掉串左右空格  去掉串左空格  去掉串右空格

别名 as   concat() as total

执行算术计算 + - * /  
select id * price
from 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 by
having

14.

15.

16.

join on
left join on
right join on

17.

union
union all

18.

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

19.

insert into 

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

20.

update table
set
where


delete 
from table
where

truncate table  重建表

21.

建表 相关
create table(

    name  char not null
)

更新
alter table vendors
add vend_phone char;
删除
drop table  vendors;

重命名
rename table customers2 to customers;

22.

未完待续…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值