1

标题有点混乱,让我解释一下。假设我有以下行:

type        name            seeds       size

fruit       apple           8           22
fruit       orange          8           14
fruit       raspberry       83          6
berry       pomegranate     201         19

我想要一个查询,它将比较所有行并返回seeds与任何其他行匹配的任何行,类型为fruit. 那可能吗?

4

1 回答 1

3

试试这个:

SELECT DISTINCT t1.*
FROM table t1
INNER JOIN table t2 ON t2.seeds = t1.seeds
WHERE t1.type = 'fruit' AND t2.type = 'fruit' AND t1.name <> t2.name

编辑

根据您的评论,要查找seeds匹配但type不匹配的项目,请尝试以下操作:

SELECT DISTINCT t1.*
FROM table t1
INNER JOIN table t2 ON t2.seeds = t1.seeds
WHERE t1.type <> t2.type
于 2013-04-07T03:09:00.363 回答