我真的不知道如何搜索这个,可能它很容易做到,但我不知道如何做到这一点。 我有一个SQL表:
| c1 | c2 | c3 | c4 | c5 |
data data data data data
所以我有5列,现在我想选择只有以下(c1,c2,c3)的行,其中该行在表格中出现的次数超过5次 像这样:
Select c1, c2, c3
From table
having count(*) > 5 and (all in that count, all rows must have the same values on c1, c2, c3)
只能通过基本的SQL查询来执行此操作。不允许使用函数,声明等。 我真的不知道我是否能很好地解释自己。
答案 0 :(得分:2)
我并不完全确定,但我的猜测是
select c1, c2, c3
from <yourtable>
group by c1, c2, c3
having count(*) > 5
答案 1 :(得分:0)
此查询将返回原始表格中的所有记录,其中c1
,c2
和c3
组合值的重复次数更多超过5次。我还在结果集中包含了实际计数。
SELECT t1.c1, t1.c2, t1.c3, t1.c4, t1.c5, t2.cardinality
FROM yourTable t1
INNER JOIN
(
SELECT c1, c2, c3, COUNT(*) AS cardinality
FROM yourTable
GROUP BY c1, c2, c3
HAVING COUNT(*) > 5
) t2
ON t1.c1 = t2.c1 AND
t1.c2 = t2.c2 AND
t1.c3 = t2.c3
答案 2 :(得分:0)
将c1,c2,c3视为单个字符串c1 + c2 + c3:
SELECT c1, c2, c3 FROM table WHERE
c1 || c2 || c3 IN (
SELECT c1 || c2 || c3 FROM table
GROUP BY c1 || c2 || c3
HAVING COUNT(*) > 5);