我有一张表,用于存储客户对产品的选择。
它存储客户编号、产品编号以及是否对产品表示感谢。我们存储是/否,因为客户必须对所有产品做出选择,以便我们可以检查他们是否已做出所有选择。
Customer | Product | Status
---------------------------
12345 | 1 | 0
12345 | 2 | 1
12345 | 3 | 1
12345 | 4 | 0
12345 | 5 | 1
23456 | 1 | 1
23456 | 2 | 0
23456 | 3 | 1
23456 | 4 | 1
23456 | 5 | 0
我想做的是检查哪些客户选择了一组特定的产品。
这可能类似于 select * from choices where product = 1 and product = 3 group by customer
但是我还必须使用 status = 1
查询产品
有没有办法在查询中解决这个问题,还是我必须求助于对某些 PHP 的几次调用?
最佳答案
select customer
from choices
where status = 1 and product in (1,3)
group by customer
having count(distinct product) = 2
关于php - Mysql:多个where查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19091065/