I need a query , in MYSQL , where I check the penultimate record and that this record is equal to a certain value and counts the number of records found .
Ex: penultimate record is from John. I need to count the number of times John appears as the penultimate record.
I tried the following by putting group by , but I did not succeed:
SELECT COUNT(*) FROM chamado AS chmd
INNER JOIN complemento AS comp ON (comp.num_chamado = chmd.num_chamado)
WHERE comp.nome like 'joao%'
GROUP BY comp.num_chamado
ORDER BY comp.id_complemento DESC LIMIT 1,1
Would anyone have any suggestions?