使用大于符号来比较BQ中的日期

时间:2018-04-23 18:50:28

标签: google-bigquery

大于符号用于比较日期,使用这个或任何其他可用的解决方案是否正确?

#standardSQL
with table1 as(
select "ProductA" as products, date '2017-1-20' as end_date union all
select "ProductB" as products, date '2017-6-20' as end_date union all
select "ProductC" as products, date '2018-1-20' as end_date union all
select "ProductD" as products, date '2018-6-20' as end_date
)
select products,end_date,if(current_date()>end_date,'outdated','current') status from table1

1 个答案:

答案 0 :(得分:1)

SELECT products,end_date, if(DATE_SUB(current_date(), INTERVAL 1 DAY)>end_date,'outdated','current') status from table1;

这是使用函数DATE_SUB获得相同结果的另一种方法。 您可以将许多不同的functions用于date数据类型。 operator“>”处理许多数据类型,包括date类型。