用于过滤信用卡的配置单元函数

mkshixfv  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(282)

有人能解释一下我听不懂的代码吗

SELECT li.user_id 
FROM loan_info li 
     INNER JOIN credit_card_info cci ON li.user_id = cci.user_id 
WHERE CAST(cci.outstanding_balance AS double) = 0.0 
  AND datediff(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'), li.last_payment_date) >= 30;

SELECT li.user_id 
FROM loan_info li INNER JOIN credit_card_info cci ON li.user_id = cci.user_id 
WHERE CAST(cci.outstanding_balance AS double) = 0.0 
  AND datediff(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'), li.last_payment_date) >= 30;
gzszwxb4

gzszwxb41#

此筛选器表示上次付款是在当前日期前30天或更长时间:

datediff(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'), li.last_payment_date) >= 30

更好地利用 current_date 而不是这样: from_unixtime(unix_timestamp(), 'yyyy-MM-dd') :

datediff(current_date, li.last_payment_date) >= 30

因为查询范围的当前日期常量是固定的,所以这样做效率更高。并为每一行计算unix\u timestamp()。另请参见以下答案:https://stackoverflow.com/a/56450811/2700344

相关问题