码迷,mamicode.com
首页 > 其他好文 > 详细

20151009学习内容:子查询、表链接

时间:2015-11-05 00:42:18      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 

--子查询
--把查询语句查询出的结果当做一个数值使用或一组数值使用
--all所有的,any任意一个,修饰符
--in(‘‘,‘‘)在数值范围内not in()不在括号的数值范围内
select price from car where name =宝马3系 325i 时尚型
select *from car where name like %奥迪%and price>=42.38
select *from car where name like %奥迪%and price>=(select price from car where name =宝马3系 325i 时尚型)

select *from car where name like %奥迪%and price>(select max(price)from car where name like%宝马%)
select *from car where name like %奥迪%and price>all(select price from car where name like %宝马% )
select *from car where name like %奥迪%and price>any(select price from car where name like %宝马% )

--in(‘‘,‘‘)在数值范围内not in()不在括号的数值范围内 == or的用法
select * from car where brand =b001or brand =b002or brand =b003 
select * from car where brand in(b001,b002,b003)
select * from car where brand not in(b001,b002,b003)

--表连接  (inner)join on内连接

select* from car
select*from brand 
select code,name,brand,brand_code  from car
 join brand on car.brand =brand .brand_code 
 select code,name,brand,brand_code  from car
 inner join brand on car.brand =brand .brand_code
 select code,name,brand,brand_code  from car
left join brand on car.brand =brand .brand_code
 select code,name,brand,brand_code  from car
 right join brand on car.brand =brand .brand_code
 
 
--子查询
select code,name,(select brand_name from brand where car.brand =brand .brand_code )as brand_name from car 
--表的拼接  用,笛卡尔积,类似for的穷举
select*from car,brand
select*from car,brand where car.brand =brand .brand_code

 

 

 

20151009学习内容:子查询、表链接

标签:

原文地址:http://www.cnblogs.com/mn-b/p/4937822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!