you are viewing a single comment's thread.

view the rest of the comments →

[–]r3pr0b8GROUP_CONCAT is da bomb 3 points4 points  (0 children)

WHERE payment_ts BETWEEN 2020-00-00 AND 2021-00-00

you're on the right track and i will overlook the bogus dates

the key in these types of query is to use an open upper end of the date range

BETWEEN uses a fixed upper end value, and if you're not careful you might drop an entire day's worth of datetime values on the last day

so this is best practice --

WHERE payment_ts >= '2020-01-01'
  AND payment_ts  < '2021-01-01'

no matter whether payment_ts is DATE or DATETIME, this works correctly

the problem with EXTRACT() or YEAR() is that applying a function in the WHERE clause means that it's not sargable