database - 连接两个表以获取确切日期
问题描述
我有两张桌子,
第一个表 --> 贷款,列 --> pos_num , pos_type
第二张表 --> 付款、列 --> pos_num 、 pos_type 、 date
我想从贷款中提取 pos_num 、 pos_type 值并放在下面的查询中
select count(1) from payment where pos_num = <value extracted from loans> and pos_type = <value extracted from loans> and date = <?>
我们如何将贷款表与付款表连接起来,以获取我们应该在付款表中为 pos_num 、 pos_type 拥有相同数据的日期,这些数据与我们从贷款表中获得的
解决方案
您可以使用 JOIN 语句获取值,例如:
SELECT pos_num , pos_type , date
FROM loans L
JOIN payment P ON L.pos_num = P.pos_num AND L.pos_type = P.pos_type;
我希望能有所帮助。
推荐阅读
- python - 追加到字典,Python
- python - 在python中查找NOT BINARY TREEE的高度和深度
- python - 如果字典中的标志为真,如何将文件从一个文件夹复制到另一个文件夹
- java - 根据进一步的条件向标准添加多个参数
- mysql - 返回已启动和已解决案例 sql 表
- python - 单独自定义 matplotlib 刻度标签
- api-platform.com - Api 平台,仅用于计算的实体,未与数据库链接 -> 标识符配置无效
- python - Try / except 在读取 json 时对 UnicodeEncodeError: 'UCS-2' 不起作用
- python - 如何聚合基本上包含相同信息但因区分大小写而被隔离的数据框列
- scala - SBT:自定义命令/任务以发布 FAT 或 SLIM jar