1

我的数据库类让我难倒了这个问题。如果有人可以帮助我,那就太好了

我有一个有 2 列的表。第 1 列是汽水类型(可口可乐、百事可乐、胡椒博士等),第 2 列是人名。人们可以喝多种苏打水。

有些条目可能是

  1. 可乐杰里米
  2. 健怡可乐山姆
  3. 胡椒博士杰里米

我必须编写一个查询来返回只喝一种苏打水的人。所以杰里米不会回来,但山姆会。问题是我不能使用 COUNT 或 GROUP(或任何聚合函数)!没有这些我该怎么做?

谢谢!

4

2 回答 2

2

你可以尝试这样的事情:

select a.soda, a.person 
  from table a
 where not exists(select 1 
                   from table b 
                  where b.person = a.person 
                    and b.soda <> a.soda)
于 2012-10-02T23:38:48.357 回答
0

如果子查询没问题,这样的事情会起作用:

select distinct * from sodas as s1 where s1.name not in (select s2.name from sodas as s2 where s2.name=s1.name and s2.soda <> s1.soda)
于 2012-10-02T23:35:02.533 回答