sql - 如何检查一条记录在不同表中重复了多少次
问题描述
我这里有两张桌子:
表格1:
process_id customer_id
16 1
21 1
22 1
表 2:
process_id customer_id
16 1
16 1
22 1
我想检查表 1 中的每一行在表 2 中重复了多少次。
例如,表 1 中的第 1 行在表 2 中重复 2 次,第 2 行重复 0 次,第 3 行重复 1 次。我不确定如何遍历表 1 中的每一行并得到这个结果。
解决方案
据我了解,这就是您所要求的:
select table1.process_id,table1.customer_id,count(table2.process_id) as table2count
from table1 left outer join table2 on table1.process_id==table2.process_id and table1.customer_id=table2.customer_id
group by table1.process_id,table1.customer_id;
推荐阅读
- ios - SWIFT - UIBarButtonItem 没有调用动作
- android - 如何在kotlin字符串中的特定单词后获取一些字母?
- javascript - 在 NextJS 中使用 useState 对象时,上下文对象为空
- html - 如何在 css/div 容器中调整背景图像的大小?
- javascript - 将结果推送到对象
- android - 由于 Hilt 错误,应用程序未初始化
- python-3.x - 计算均匀性的度量标准,对较低的值进行惩罚
- r - 根据一组字符串条件创建一个新列
- javascript - Javascript reverse() 在循环中不起作用
- vue.js - 如何使用 Vue js 添加上一个和下一个按钮?