有人能解释一下我听不懂的代码吗
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;
1条答案
按热度按时间gzszwxb41#
此筛选器表示上次付款是在当前日期前30天或更长时间:
更好地利用
current_date
而不是这样:from_unixtime(unix_timestamp(), 'yyyy-MM-dd')
:因为查询范围的当前日期常量是固定的,所以这样做效率更高。并为每一行计算unix\u timestamp()。另请参见以下答案:https://stackoverflow.com/a/56450811/2700344