0

I want to get some Data from my db with the following statement:

SELECT * 
FROM Gasstation
WHERE (LOWER(Place) LIKE 'k%ln') 
   OR (LOWER(Place) LIKE 'd%sseldorf')
  AND (DATE(Time) BETWEEN 2021/10/06 and 2021/10/11)
  AND Distance <= 0.3;

I also tried it with

WHERE ((LOWER(Place) LIKE 'k%ln') 
       OR (LOWER(Place) LIKE 'd%sseldorf'))

I need the "DATE(Time)" format here because in the Time column there is also the clock time saved like this : 2021-08-25 11:59:37.

I have already tried it with other statement like comparing the times with '<=' and '>=' and took out some brackets but it always shows data that is older than the date it should be. Like from August and the distance is also being ignored because it shows data with distance that is bigger than 0.3.

If I use it like this it works fine:

SELECT Date(Time), Distance 
FROM Gasstation 
WHERE Distance <= 0.4;

Thank you already!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Erwin109
  • 17
  • 6
  • It doesn't. Think about what that statement says, and the precedence of logical operators. `A OR B AND C AND D`. `AND` has higher precedence so the condition is equivalent to `A OR (B AND C AND D)`. That's not a bug. That's how logical operators work, in all languages – Panagiotis Kanavos Oct 11 '21 at 13:27
  • Also, ` BETWEEN 2021/10/06 and 2021/10/11` compares a date with the result of the division `2021/10/06`, not a date. If you want to hard-code dates use the unseparated format ie `BETWEEN '20211006' AND '20211011'`. – Panagiotis Kanavos Oct 11 '21 at 13:30
  • I still don't get how I need to write it. I tried like everything and sometimes it shows me some values but still ignores the date and sometimes it shows no value. Still thank you already – Erwin109 Oct 12 '21 at 08:41
  • I got it. Thank you – Erwin109 Oct 12 '21 at 08:50

0 Answers0