首页 > 解决方案 > 连接两个表以获取确切日期

问题描述

我有两张桌子,

第一个表 --> 贷款,列 --> 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 拥有相同数据的日期,这些数据与我们从贷款表中获得的

标签: databaseoracleplsqloracle-sqldeveloper

解决方案


您可以使用 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;

我希望能有所帮助。


推荐阅读