I'm developing a small vaccine control system and I'm having a hard time performing a select.
I have a record of dogs, another of types of vaccines and a third of vaccine per dog, where I group the dog's id, type id of the vaccine (v10, antirabica, fleas, etc.), application date and the date of the next application.
I'm trying to look at this vaccine record per dog only the latest application per dog grouping and type, for example:
Cachorro Vacina DtAplicação DtProxima 1 1 10/03/16 10/03/17 1 1 10/03/15 10/03/16 1 2 10/03/16 10/03/17 2 1 10/03/16 10/03/17 2 2 10/03/16 10/03/17
In this example I need to display all records, except the second (because it is an already reinforced application of the same type for the same dog).
Here's an example of what I'm trying to do to get the vaccines to be applied in the current week but not filtering properly:
SELECT c.nome, cv.vacinaoid, max(cv.proxima) FROM bicho_cachorro c
INNER JOIN bicho_cachorro_vacina cv ON c.id = cv.cachorrooid
WHERE WEEKOFYEAR( cv.proxima ) = WEEKOFYEAR( NOW() )
group by 1, 2 order by 3
How can I do this search? I tried to make a distinct
of c.nome
and cv.vacionaoid
, but could not make the two fields together.