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%'; 查看与字符变量相关的
校对关系?指的是当前字符集内字符之间的比较关系
gbkvsutf8:gbk占两个字节utf8占三个字节
set names gbk;
set namesutf8;
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 doubledecimal(大致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 wherecountry='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;
sql分组排序笔记
文章图片

我们可以使用 coalesce 来设置一个可以取代 NUll 的名称,coalesce 语法:
select coalesce(a,b,c);
【sql分组排序笔记】sql分组排序笔记
文章图片


    推荐阅读