mysq笔记

create database if not exists test; 为了不产生错误,创建数据库时加上一些 简单的逻辑判断

drop database if exists test; 为了不产生错误,在删除数据库时加上一些简单的逻辑判断

show database; 查看数据库列表

create  table  if not exists test(id varchar(32)); 为了不产生错误,在创建表格时加上一些简单的逻辑判断

drop table test; 删除表格

insert into table_name(id,...,...)values(1,...,....),(2,...,...); 向表格内插入数据

 

schemata 所有的库

tables  所有的表

columens  所有的列

select * from user where name ='XXX‘;

select * from user(表名) where(+条件) id = '1' and  name = 'lisi';

select * from user  where  xxx and xxx or xxx;

and  : true ,false ,数字,null,条件语句

   = ,!=,<,>,<>,like+(%)模糊查询

 

select count(*) as(重命名) 'xxx',列名,222 from user where name = 'xxx'; 查询条数

select conat(id,name) from user where id; 拼接

select substr(列名,起始位置,偏移量) from user where id=1;截取字符串

select length(name) from user where id=1; 字符串的位数

select substr(name,length(name)-2,3) from user;

select substr (name,-3,1) from user; 截取倒数第三位

select min(id) from user; 取列内最小值

select avg(id) from user; 取列内平均值

select sum() from user; 取列内所有值之和

select group_concat(name) from user; 把一列全部列出

字符串函数

select ascii();ascii函数

select left(str,x);返回str字符串中最左边的x个值

select position(int in substr);第一个字符串在第二个的哪个位置

控制流函数

select case when 1>0 then 'big' else 'small' end; 如果1>0 则输出 big 否则 输出 small

select if(1>0,1,2);如果1>0输出1,否则输出2

联合查询

join 内关联

left join 左关联

right join 右关联

inner join 内关联

xxx  union  xxx

查询列的个数必须一致 union select  生成一个临时表

select name,grade from user u left join grade g on u.id=g.user_id; 把user中的name和grade中的grade用left join(左关联)关联起来,用的是id

 

select * from user order by name; 按照名字排序  asc 升序  aesa 降序

转载于:https://www.cnblogs.com/Blizzard-player/p/8857744.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值