2021年5月1日星期六

MySQL query to show pets that did not take a certain vaccine?

I have one table

petVac(pet, vaccine)

the data looks like this:

   pet   vaccine      P1 ​| V1      P2 | V2       P3 | V3      P1 | V3      P2 | V4  

I want to know if a query could be created that would list the pet and vaccine that a pet has not taken yet.

For example, it would result in something like:

pet |vaccineNotTaken    P1    V2  P1    V4  P2    V1  P2    V3  P3    V1  P3    V2  P3    V4  

etc...

I tried doing select pet, vaccine from petVac where not exists (select distinct pet, vaccine from petVac); but it results in an empty set. I am confused on how to go about this, is it possible?

https://stackoverflow.com/questions/67352858/mysql-query-to-show-pets-that-did-not-take-a-certain-vaccine May 02, 2021 at 11:57AM

没有评论:

发表评论