日期之间(开始和现在)

时间:2019-08-16 19:33:52

标签: sql presto

不确定如何使用NOW()函数。似乎应该是直截了当的,但是我没有运气

SELECT DISTINCT field
FROM table
WHERE field BETWEEN '2019-01-01' and NOW()

field = varchar

1 个答案:

答案 0 :(得分:4)

您应该匹配数据类型,以避免隐式转换:

SELECT DISTINCT field
FROM table
WHERE CAST(field AS DATE) BETWEEN DATE '2019-01-01' AND CURRENT_DATE;

SELECT DISTINCT field
FROM table
WHERE DATE(field) BETWEEN DATE '2019-01-01' AND CURRENT_DATE;