• Is a good thing that you posted DDL, sample data and expected results.

    But the problem is it's not matching with each other.

    You might want to check your definition on date_block field from Vehicle table. Is a varchar with no length defined, that will truncate the values to a lendth of 1.

    Another thing that had problems is that your query uses more fields than the vehicle table has (that might be a problem caused by simplifying the query to post it here).

    The last thing, is that you have sample data for vehicles 724 and 725 and expected results for 28, 29 and 30.

    You seem to be very close to your result, but I'm not sure on what is missing unless you give me the correct expected results.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2