0
点赞
收藏
分享

微信扫一扫

左连接查询、右连接查询、全连接查询、嵌套查询(where、having、from、select)

外连接查询


比较两个表里的数据不同的

左连接 --用左表的数据和 右表的数据作比较


select 表头名 from  表名1 left join 表名2   on  连接条件;


左连接的输出结果

左表表表头的数据全部显示,右表仅显示链接条件匹配的行,诺右表的输出的行比左表的行少,使用null补全少的行,然后输出显示



select 表头名 from  表名1 left join 表名2   on  连接条件 [where | group by | orderby | having | limit];















右链接



去除重复输出


(select查询命令) union (select查询命令)


不去除重复行输出


(select查询命令) union all (select查询命令)







select dept_id , count(name) from employees group by dept_id having count(name) <  (select count(name) from where employees dept_id = (select dept_id from  departments where dept_name= "开发部"));


select dept_id,count(name) from employees group by dept_id having count(name) < (select count(name) from employees where dept_id = (select dept_id from departments where dept_name="开发部") );



建表:定义文件名,定义存储数据的表头名 及 表头存储数据使用的数据类型

create table 库名.表名 (

表头名 数据类型, 表头名 数据类型


);


查看表头desc 表头  desc stuinfo

add 添加  first 首位    after后面

add 都需要写表头名和数据类型



drop 删除

alter table drop user email

删除user表里面的email



modify 修改数据类型及约束条件

change 修改表头名

rename 修改表名



alter table user add email after name添加表头命令

在user表里面把email添加到name的后面


复制表练习和cp命令是一样的功能


仅拷贝表头(不拷贝数据)

拷贝表头+数据 create table 库.表select 查询命令;



字符类型

姓名 收货地址 家庭住址 有汉字就是字符类型

char

varchar

数值类型 工资 身高,由数字组成的,成绩,提供

整数类型 是整数 (不存储小数点,只能存储整数)

根据存储数字范围不同分为

tinyint 微小整数  

smallint 小整数

mediumint 中整数

int 大整数

biging 极大整形

unsigned 使用无符号存储范围

左连接查询、右连接查询、全连接查询、嵌套查询(where、having、from、select)_表名





浮点类型(能存储小数的类型)

float 单精度   4字节

double 双精度 8字节



create table db1;

creat table db1.t1(年龄 tinyint unsigned , 工资smallint ,奖金 float);




枚举类型 表头的值 在定义的范围里选择

性别

单选 enum (值列表)

多选 set(值列表)

create table db1.t2( 性别 enum(“男”,”女”)) , 爱好 set(“IT”,”看书”,”打游戏”);





日期时间类型






举报

相关推荐

连接查询

0 条评论