博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql join 的同时可以筛选数据
阅读量:6879 次
发布时间:2019-06-27

本文共 673 字,大约阅读时间需要 2 分钟。

看sql

select a.id as goods_id,a.name,a.store_id,a.salecount,a.logoimg,b.name as store_name,count(c.id) as mall_goods_count,c.type from sh_goods a LEFT JOIN sh_store b on a.store_id = b.id LEFT JOIN sh_mall_goods c on a.id = c.goods_id and c.mall_id = 9 where a.store_id in (select id from sh_store where user_id in (select id from sh_user where agent_id = 13 and status = 1) and status = 1) and a.status = 1 group by a.id;

这里面用了多个子查询,与join关联。

其中

LEFT JOIN sh_mall_goods c on a.id = c.goods_id and c.mall_id = 9

不仅有关联条件,还对sh_mall_goods表进行了筛选,只选出mall_id为9的数据,进行关联。

这很有意思。

下面是查询结果,有筛选与没筛选的区别。

 

本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5078163.html,如需转载请自行联系原作者

你可能感兴趣的文章
mysql join 的同时可以筛选数据
查看>>
Code First开发系列之管理并发和事务
查看>>
Spark SQL概念学习系列之为什么使用 Spark SQL?(二)
查看>>
VirtualBox-Linux系统安装增强功能
查看>>
ssh/ssh2登录
查看>>
mongodb对数组元素及内嵌文档进行增删改查操作(转)
查看>>
【python3.5】安装lxml中没有etree模块的问题解决方法
查看>>
pgpool-II的性能缺陷
查看>>
spin_lock浅析【转】
查看>>
MVC前台Post/Get异步获得数据时参数的取值问题
查看>>
8086/8088指令详解
查看>>
iOS:自定义代码块{ }
查看>>
C# 远程链接指定计算机,获取该计算机的计算机名等信息
查看>>
OpenGL入门笔记(十一)
查看>>
windowsXP用户被禁用导致不能网站登录
查看>>
第 8 章 TokyoCabinet/Tyrant
查看>>
智慧城市逐步推进 未来城市建设突破口分析
查看>>
是谁在推动路由器智能连接功能的普及?
查看>>
物联网软件更新政策不明 智能冰箱也易沦为犯罪工具
查看>>
基于 SaaS 解决库存问题, Nextail 获 160 万美元融资
查看>>