我有两个表user_updated_details
和user_details
。我必须从updated_file_cap
表中获取特定date_current
的{{1}}和user_updated_details
列值,以及使用user_id
运算符指定的日期。
对于具有BETWEEN
列的匹配记录,我正在获取记录。对于不匹配的日期,我应该从user_details表中获取值。不确定如何执行此操作。请协助
考虑date_current
表有2条记录,例如
user_details
考虑user_id | user_name | file_cap
-------------------------------
111 | Karthik | 5
---------------------------------
222 | Vinod | 6
--------------------------------
表有3条记录,例如
user_updated_details
要查找匹配的记录,我们可以使用以下查询。
user_id | date_current | updated_file_cap
---------------------------------------------
111 | 2019-03-29 | 10
222 | 2019-03-29 | 11
111 | 2019-04-01 | 9
----------------------------------------------
当前结果集将是:
select date_current , updated_file_cap, user_id
from user_updated_details
where user_id=111
and date_current BETWEEN '2019-04-02' AND '2019-03-29'
ORDER BY date_current DESC;
但是我的要求是,对于不匹配的值(在 date_current | updated_file_cap | user_id
------------------------------------------
2019-03-29 | 10 | 111
2019-04-01 | 9 | 111
------------------------------------------
运算符中指定),例如 2019-03-30 , 2019-03 -31 , 2019-04-02 ,我应该从user_details表的file_cap列中获取updated_file_cap值。
我需要一个查询,该查询给出预期输出应如下所述
BETWEEN