Supposing I have a table consisting of something like:
01/01/2020 | A | B | C |
02/01/2020 | 3 | 5 | null |
03/01/2020 | 8 | 3 | null |
04/01/2020 | 3 | 4 | null |
05/01/2020 | 5 | 9 | 3 |
06/01/2020 | 3 | 3 | null |
07/01/2020 | 1 | 2 | null |
08/01/2020 | 5 | 9 | 5 |
How can I write a query to return the largest number of consecutive nulls in column C?
In this case, the answer should be 3.
I’ve tried searching online and asking LLMs but I’m yet to find an answer that aids me.
Kind regards and thank you for your help.
I’ve tried queries like:
SELECT
`C`,
COUNT(*) AS table_name
FROM
(SELECT
`C`,
IFNULL(`C`, 0) AS points
FROM
table_name) AS subquery
GROUP BY
`C`
HAVING
COUNT(*) > 1;
But this isn’t looking at consecutive nulls, it’s just counting the groups of different values for the columns in general. I’m not sure where to even begin at this point.
4dmh4 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.