-2

我有这张桌子

id 所有者组模型  
1 1 形状圆形  
2 1 个矩形  
3 1 个形状  
4 2 水果 苹果  
5 2 水果 橙子  
6 2个水果香蕉  
7 3 个形状的圆圈  
8 3 个形状的矩形  
9 3 形星

每个所有者选择一个组并输入 3 个选项,现在我想找到选择形状并输入圆形和星形的所有者。

它必须返回所有者 id = 3

4

2 回答 2

1

假设groupmodel对每个人都是独一无二的owner

SELECT  a.owner
FROM    tableName a
WHERE   a.[group] = 'shapes' AND
        a.model IN ('circle','star')
GROUP   BY a.owner
HAVING  COUNT(*) = 2

否则,您需要唯一计算model

SELECT  a.owner
FROM    tableName a
WHERE   a.[group] = 'shapes' AND
        a.model IN ('circle','star')
GROUP   BY a.owner
HAVING  COUNT(DISTINCT a.model) = 2
于 2013-09-23T18:50:57.357 回答
0

在指定的参数内,这将起作用: SELECT owner WHERE [group] = 'shapes' AND model = 'circle' INTERSECT SELECT owner WHERE [group] = 'shapes' AND model = 'star'

于 2013-09-23T19:22:28.687 回答