本节内容:
mysql多表子查询与左连接
需求:
如何在mysql中实现复杂查询、多表查询包含子连接的?
解决方法:
复制代码 代码示例:
select c.*,d1.debt,d2.hasorders from dw_customerinfo c left join (select d.customerid, sum(d.price)>sum(d.pay) debt from dw_ordersdetail d where d.state='1' and d.pubtime<= now() group by d.customerid) d1 on c.id=d1.customerid
left join (select d.customerid, count(d.customerid)>0 hasorders from dw_ordersdetail d group by d.customerid) d2 on c.id=d2.customerid
方法1:测试未通过
复制代码 代码示例:
Select * FROM t1 LEFT JOIN (t2, t3, t4) ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
方法2:测试通过
复制代码 代码示例:
SELECT artists.Artist, cds.title, genres.genre
FROM cds
LEFT JOIN genres N cds.genreID = genres.genreID
LEFT JOIN artists ON cds.artistID = artists.artistID;
您可能感兴趣的文章:
mysql子查询的实例总结
mysql子查询使用EXISTS命令的例子
mysql子查询中EXISTS用法的例子
mysql子查询的五种方式
mysql 子查询与join性能对比
mysql子查询的用法举例
mysql update实现子查询的实例分享
mysql in 子查询效率慢的优化方法详解