Presto - 如何使用 date_trunc() 函数过滤从当年开始的记录?
Presto - How to filter for records starting from current year using date_trunc() function?
想知道如何筛选今年年初以来的记录?
我的查询如下:
SELECT date_id, item_id, product_name, product_price, sum(order*product_price) as revenue
FROM sales_table
WHERE year(date_id) >= date_trunc('year', current_date)
执行这段代码时'year'出现错误
有人可以建议吗?非常感谢!
你的方法是正确的,除了 date_trunc
returns 一个日期,而不是年份:
presto:tiny> SELECT date_trunc('year', current_date);
_col0
------------
2020-01-01
假设 date_id
是 date
数据类型,您的查询将是:
SELECT * FROM sales_table WHERE date_id >= date_trunc('year', current_date);
想知道如何筛选今年年初以来的记录?
我的查询如下:
SELECT date_id, item_id, product_name, product_price, sum(order*product_price) as revenue
FROM sales_table
WHERE year(date_id) >= date_trunc('year', current_date)
执行这段代码时'year'出现错误
有人可以建议吗?非常感谢!
你的方法是正确的,除了 date_trunc
returns 一个日期,而不是年份:
presto:tiny> SELECT date_trunc('year', current_date);
_col0
------------
2020-01-01
假设 date_id
是 date
数据类型,您的查询将是:
SELECT * FROM sales_table WHERE date_id >= date_trunc('year', current_date);