select * from table1 ;
-- BETWEEN 用法
select * from table1 where kssj BETWEEN '2019-05-01' and '2019-05-01';
select * from table1 where kssj >= '2019-05-01' and kssj<= '2019-05-01';
-- join用法
select * from table1 ;
select * from table2 where hdid ='hdid2019041614955744';
-- =用法
select a.hdid, hdbt ,hdzt from table1 a,table2 b where a.hdid =b.hdid
-- =作用:a表中的hdid 去b表中从上到下遍历一遍,找到几个满足where条件的,就显示几条,可用distinct去重
select a.hdid, hdbt ,hdzt
from table1 a
inner join table2 b
on a.hdid=b.hdid
-- inner join 此条查询sql 等价于上面的=用法
select a.hdid, a.hdbt ,a.hdzt , b.zpid
from table1 a
left join table2 b
on a.hdid=b.hdid
-- left join 左连接 即使右表中没有匹配,也从左表返回所有的行
select a.hdid, a.hdbt ,a.hdzt , b.zpid
from table1 a
left join table2 b
on a.hdid=b.hdid
except
select a.hdid, hdbt ,hdzt,b.zpid
from table1 a
inner join table2 b
on a.hdid=b.hdid
-- except 来验证数据,查出来都是没有活动照片的活动
select a.hdid, a.hdbt ,a.hdzt , b.zpid
from table1 a
right join table2 b
on a.hdid=b.hdid
-- right join 即使左表中没有匹配,也从右表返回所有的行
select a.hdid, hdbt ,hdzt
from table1 a
inner join table2 b
on a.hdid=b.hdid
-- 全连接 只要一个表中有数据,就查出这条数据