select producten_pid from prodsymp where symptomen_id = 11 and symptomen_id = 18;
我正在尝试在mysql表上执行上述select语句。 但是我没有得到应有的结果。 我在做什么错了?
谢谢您的回答。 当时的想法是为问题和解决方案创建一个数据库, 一个问题可以有多个解决方案,而一个解决方案可以解决多个问题。 我创建了这个参考表'probsol',其中同时引用了问题和解决方案表,如下所示。
psid 1 2 3 4 5 6 7 8 9
pid 11 11 12 12 17 18 18 19 20
sid 18 9 18 10 10 18 9 13 13
现在,我正在尝试创建一个查询,以查找针对多个问题的单个解决方案,如下所示:
select sid from prodsymp where pid = 11 and pid = 12;
此查询的结果应为18,但我得到0个结果。
答案 0 :(得分:1)
Mysql运行正常。您要求在symptomen_id
同时位于11和18的行。不可能有这样的行,因此您不会得到任何结果。
也许您想使用OR
。
答案 1 :(得分:1)
您的逻辑是错误的。 symptomen_id
不能同时存在。使用or
。
更好的是,像这样使用in
:
select producten_pid from prodsymp where symptomen_id in (11, 18).
编辑:
您编辑了问题之后,您的问题就变得完全不同了。
也许此查询可以帮助您
SELECT
sid,
count(*) as cnt
FROM
producten_pid
where
pid in (
11,12
)
group by
sid
having
count(*) > 1