1

I have written this script:

SELECT id_pass, max(dt) FROM parking_pass_move
WHERE type_error is null and id_pass = 1784
GROUP BY id_pass
HAVING max(dt) < '2021-07-02' 

And it returns:
result

OK! But when I change my having row to:

HAVING max(dt) < '2021-07-01'

Or even:

HAVING max(dt) < '2021-06-27'

I have this:
result

Such data definitely exists, so I don't understand what to do:
result

Structure of the table:
table types

I tried to change 'dt' to date and timestamp, tried to do same with date in having row. It didn't help.

My aim with this code is to take last move for selected pass and date.

nyangoodye
  • 13
  • 3
  • Please provide a [mre] including DDL and DML as code-formatted text so we can try things out – Mark Rotteveel Jul 09 '21 at 12:17
  • 1
    In any case, your screenshot does not demonstrates that such data exists, because all it shows is data with ID_PASS = 2798, while you're querying for ID_PASS = 1784. – Mark Rotteveel Jul 09 '21 at 12:18
  • 1
    So for this id the max date is `2021-07-01`, which is not `< 2021-07-01` and certainly not `< 2021-06-27`. Do you perhaps mean to get the max of the values prior to `2021-07-01`? In that case use a `WHERE` to filter before aggregation. – HoneyBadger Jul 09 '21 at 12:27
  • @HoneyBadger, hello. I nedd timestamp which less than written date. So for `2021-07-01` it would be `29.06.2021 17:15:40` – nyangoodye Jul 09 '21 at 16:06
  • 2
    go http://dbfiddle.uk/?rdbms=firebird_3.0 and make sample table with sample data and then we can talk about real table structure, real values and real queries. As of know it is merely chasing shadows... Hard to do and not precise – Arioch 'The Jul 09 '21 at 16:08

0 Answers0