vendredi 16 octobre 2020

SQL question: how do I find the count of IDs that are always mapped to a 'true' field in another table

I have a database that collects a list of document packages in one table and each individual page in another table

Each page has a PackageID connecting the two tables.

I'm trying to find the count of all packages where ALL pages connected to it have a boolean field (stored on the page table) of true. Even if 1/20 of the pages connected to the packageID is false, I don't want that packageID counted

Right now all I have is:

SELECT COUNT(DISTINCT pages.package_id)
FROM pages
WHERE boolean_field = true

But I'm not sure how to add that if one page w/ that package_id has the boolean_field != true than I don't want it counted. I also want to know the count of those packages that have any that are false.

I'm not sure if I need a subquery, if statement, having clause, or what.

Any direction even if it's what operators I should study on would be super helpful. Thanks :).

Aucun commentaire:

Enregistrer un commentaire