mysql - 如何在一个列上连接两个表,同时保留另一列中的值?
问题描述
我有两张桌子。
链接表
URL Links
example.com/1 6
example.com/2 2
example.com/3 4
pages_table
URL
example.com/2
example.com/4
如何以保留链接数量的方式组合所有 URL?
期望的结果:
URL Links
example.com/1 6
example.com/2 2
example.com/3 4
example.com/4 null
解决方案
在 MySQL 中,您可以模拟full join
withUNION ALL
和聚合:
select url, max(links) links
from (
select url, links from links_table
union all
select url, null from pages_table
) t
group by url
推荐阅读
- powershell - 用于在 powershell 中创建名称的循环逻辑
- git - 获取 git 存储库中第一次提交的提交哈希
- javascript - 我无法使用 npm 安装 Webpack
- javascript - Javascript中基于交集而不重复的累积合并数组
- java - 检查扑克手时for循环停止的问题
- android - 除非用户清除 Play 服务缓存,否则 Android 应用内购买会失败
- python - 使用启用了`usetex`的f-string在pyplot文本中显示%
- assembly - 通过 8042 PS/2 控制器重置后,QEMU 不会重新启动我的操作系统
- python - 如何为这个稍微复杂的方法调用添加参数?
- amazon-web-services - 在 DynamoDB 中使用 json 作为排序键/分区键值的好习惯吗?