gpt4 book ai didi

mysql - 元素重复至少 3 次

转载 作者:行者123 更新时间:2023-11-30 22:35:59 26 4
gpt4 key购买 nike

有没有办法在不使用 Count 和 Group By 的情况下判断一个元素是否在列中至少出现 3 次?

EDIT: The answer is expected in SQL (mysql or oracle11g) in which only SELECT, FROM, WHERE and JOINS are used. And of course, all the logical operators and quantifiers as RELATIONAL CALCULUS WITH TUPLES has NO tools at all.

Example of tuples:

{ t : {name} | ∃ s : {name, wage} ( Employee(s) ∧ s.wage = 50.000 ∧ t.name = s.name ) }

here, the limitations of Relational Calculus with tuples are clear.

No CTE's, no group by, no row tools, no distinct, no count, no views, no create, no insert, no alter. None of those awesome SQL tools.

我不想使用 Count 和 Group By 的原因是因为我会把它带到 Relational Calculus with Tuples,它不允许使用这些工具。

举个例子:

假设有一个表 ORDER (Id_article, Id_Provider),其中两个 ID 都是外键。

查询:获取至少被订购3次的所有文章。

令表 ORDER 为:

   Id_Article      Id_Provider

1 A
1 B
1 B
2 C
2 C
3 A

查询结果应该只有元素1,在Id_Article中出现了3次。

最佳答案

向下知道这是否回答了您的问题。但是 oracle 有一个 row_number 函数

在这种情况下,partition_by 对每篇文章重新开始计数。

SQL Fiddle Demo

WITH CTE AS (
SELECT "Id_Article",
"Id_Provider",
ROW_NUMBER() OVER
(PARTITION BY "Id_Article" ORDER BY "Id_Provider") AS rn
FROM Table1
)
SELECT DISTINCT "Id_Article"
FROM CTE
WHERE rn >= 3;

关于mysql - 元素重复至少 3 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32556972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com