我正在PostgreSQL SQL中两个日期范围之间查询数据,但没有得到预期的结果。
select
pi_serial,
amount_in_local_currency,
status,
proforma_invoice_date
from proforma_invoice
where created_by = 25
and proforma_invoice_date BETWEEN '03/01/2018' and '09/03/2018'
order by proforma_invoice_date
现在查看查询和proforma_invoice_date列。在此查询中,我正在搜索03/01/2018至09/03/2018之间的数据。日期格式为(DD / MM / YYYY),并且字符不同。我在这张照片中得到的结果。它只是根据一天的时间给我结果,而不是整个日期格式。我已经尝试了很多事情,日期转换,字符变化至今。但是我没有得到任何预期的结果
答案 0 :(得分:0)
您的查询绝对正确。只需将其更改如下
select pi_serial, amount_in_local_currency, status, proforma_invoice_date
from proforma_invoice
where created_by = 25
and to_date(proforma_invoice_date, 'DD/MM/YYYY') BETWEEN to_date('03/01/2018', 'DD/MM/YYYY') and to_date('09/03/2018', 'DD/MM/YYYY')
order by proforma_invoice_date