话论mysql中的那些‘连接’

1,myqld的子查询

2,mysql的自连接

3,mysql的外连接

4,mysql的内连接,

尼玛,都是啥东西,不懂,更不知道怎么用!!!

比如:对每个客户下了多少订单进行记数,包括至今尚未下订单的客户。

select customer.cust_id,customers.cust_name,count(orders.order_num) as num_ord from customers left outer join orders on customers.cust_id = orders.cust_id group by customers.cust_id;

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

尼玛呀,这不都可以吗,没算过大数据量的数据,不知道性能有什么不同!!!

猜你喜欢

转载自hp850789392.iteye.com/blog/1830620
今日推荐