'select the dates when a customer doesn't meet the requirements in Postgresql

I have a table of "customers", "count" and "datefield". I want to get the dates when a customer has a "count" of below 100. If the "count" remains below 100 then I am expecting only the first date when the "count" dropped below 100. If the "count" goes back up to 100 and drops again, I need that date when the "count" dropped below 100 again.

example data:

Customer Count datefield
A 99 1/2/2019
A 105 21/2/2019
A 69 02/3/2019
A 68 12/3/2019
A 160 14/3/2019
A 79 21/3/2019

I am expecting a SQL statement which would return the times the customer had a count below 100.

Expected result:

Customer Count datefield
A 99 1/2/2019
A 69 02/3/2019
A 79 21/3/2019

Any help would be appreciated! Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source