I have a quite simple question, however I couldn't figure out the answer yet.
我有一个非常简单的问题,但我还没弄清楚答案。
For example I have a row with numbers:
例如,我有一行数字:
id number
1 5
2 72
3 14
4 72
5 16
6 5
7 14
8 5
I would like MySql to start looking from row 1 and decide if it's row "number" exists (one or more times) or not in the whole table. After that it should check the second row, etc.
我希望MySql从第1行开始查看并确定它是否存在(一次或多次)行,或者不存在于整个表中。之后应检查第二行等。
In this example it should first search for number "5" and it should let me know that there are more than 1 occurance, than go to the second row and check 72, etc.
在这个例子中,它应首先搜索数字“5”,它应该让我知道有超过1次出现,而不是去第二行并检查72,等等。
I don't know if I was clear about what I'd like, if I didn't please let me know and I'll try to explain better.
我不知道我是否清楚自己喜欢什么,如果我没有请让我知道,我会尝试更好地解释。
Thanks.
3 个解决方案
#1
0
SELECT number, count(1) as cnt FROM table GROUP BY number HAVING cnt > 1
#2
0
what's the desired end result? if to find which "number"s occur more than once then simple "group by" on it with count will do
什么是期望的最终结果?如果要查找哪个“数字”不止一次出现,那么简单的“分组”就可以了
select number, count(1) from mytable group by number
add "having" to show only those with count(1) > 1
添加“having”仅显示count(1)> 1的那些
#3
0
You want to group by. Like this:
你想分组。像这样:
Select number, count(number)
From table_name
group by number
#1
0
SELECT number, count(1) as cnt FROM table GROUP BY number HAVING cnt > 1
#2
0
what's the desired end result? if to find which "number"s occur more than once then simple "group by" on it with count will do
什么是期望的最终结果?如果要查找哪个“数字”不止一次出现,那么简单的“分组”就可以了
select number, count(1) from mytable group by number
add "having" to show only those with count(1) > 1
添加“having”仅显示count(1)> 1的那些
#3
0
You want to group by. Like this:
你想分组。像这样:
Select number, count(number)
From table_name
group by number