sql分组排序笔记

mysql -u root -p
 use db;
 create table teacher(id int primary key auto_increment,t_name varchar(20),c_name varchar(20));
 show databases;
 show tables;
 desc teacher;
 select t_name,c_name from teacher;
 insert into teacher(t_name,c_name) values("frx","Chinese");
 update teacher set t_name='zyl',c_name='Math',id='34' where id=2;
 delete from teacher where id=34;
 show variables;查看所有的变量
 show variables like 'character_set%';查看与字符变量相关的
 校对关系?指的是当前字符集内字符之间的比较关系
 gbk  vs  utf8:gbk占两个字节   utf8占三个字节
 set names gbk;
 set names  utf8;
 create table tab_int(a tinyint unsigned,b tinyint);  unsigned无符号  默认是有符号的
 zerofill定义宽度:通过规定数据的显示宽度,达到统一显示的目的。
 alter table tab_int add c tingyint(2) zerofill;
 
 mysql中没用boolean类型  ,自己定义0位假   非0为真
 
 小数  float double  decimal(大致9个数据采用4个字节)
 浮点数
 单精度:默认的精度是7个但是不准 可能取决于cpu
 双精度:默认有效位17个, 通常也认为是16个左右
 
  select * from teacher where t_name like 'f%';
  select country from websites union select country from apps order by country;
  select country from websites union all select country from apps order by country;
  select country,name from websites where country='CN' union all select country,app_name from apps where            country='CN' order by country;
 
 
   select name,count(*) from employee_tbl group by name;//根据name进行分组
   WITH ROLLUP 可以实现在分组统计数据基础上再进行相同的统计(SUM,AVG,COUNT…)。
   select name,sum(singin) as singin_count from employee_tbl group by name with rollup;
   
   我们可以使用 coalesce 来设置一个可以取代 NUll 的名称,coalesce 语法:

   select coalesce(a,b,c);


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值