I have a problem to make a query for view data in postgresql. I want to view data with 2 condition :
- where employeeId
- and between daterange
Heres my Query:
Select *
from employee
where employeeId = 3
and date(created_at) = between '2022-08-29' and '2022-08-31'
I have run that query but show error:
Reason:
SQL Error [42601]: ERROR: syntax error at or near "date" Position: 1`
The type data of column created_at
is timestamp.
My questions is: What is correct query for view data from that conditions?
CodePudding user response:
Remove the =
operator from your query, the BETWEEN
does not require the =
Select * from employee where employeeId = 3 and date(created_at) between '2022-08-29' and '2022-08-31'
CodePudding user response:
You can use arithmetic operation
Select *
from employee
where employeeId = 3
and created_at>='2022-08-29'
and created_at< '2022-09-01'