码迷,mamicode.com
首页 > 数据库 > 详细

mysql(3)

时间:2015-08-10 18:04:07      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

1.子查询

 select cust_id from orders
 where order_num in (select order_num from orderitems 
                                where prod_id=‘TNT2‘)

 

SELECT cust_id,cust_name,(select count(*) from orders where orders.cust_id=
customers.cust_id)  from customers;

等效于select q.cust_id,q.cust_name ,count(order_num) from  orders p right join  customers q  
on p.cust_id=q.cust_id group by q.cust_id

2.等值连接(内部连接)

mysql(3)

标签:

原文地址:http://www.cnblogs.com/Citizen/p/4718512.html

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