如何计算重复行?
我希望能够从包含两个整数值的元组创建直方图。
这是查询:
SELECT temp.ad_id, temp.distance as hits FROM (
'UNION ALL .join(cupound_query)' # python
) as temp GROUP BY temp.ad_id,temp.distance
对于此输入:
(51, 5)
(51, 0)
(51, 3)
(51, 0)
(88, 2)
(88, 2)
(88, 2)
(84, 1)
(81, 9)
将是:
(88,2) : 3
(51,0) : 2
(51,3) : 1
(51,5) : 1
(84,1) : 1
(81,9) : 1
如何创建这些值的直方图?
换句话说,我如何计算一行中有多少次重复?
I want to be able to create a histogram out of a tuple containing two integers values.
Here it is the query:
SELECT temp.ad_id, temp.distance as hits FROM (
'UNION ALL .join(cupound_query)' # python
) as temp GROUP BY temp.ad_id,temp.distance
For this input:
(51, 5)
(51, 0)
(51, 3)
(51, 0)
(88, 2)
(88, 2)
(88, 2)
(84, 1)
(81, 9)
Would be:
(88,2) : 3
(51,0) : 2
(51,3) : 1
(51,5) : 1
(84,1) : 1
(81,9) : 1
How can I create a histogram of those values?
In other words, how can I count how many times a row has a duplicate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题留下了解释的空间。此测试用例显示 2 个嵌套步骤:
每个值有多少个重复项?
结果:
读取:
ad_id 62
存在 1x,ad_id 288
存在 4x,...如何计算行有重复项的次数?
结果:
读取:出现 8 次“
ad_id
是唯一的”,出现 7 次“2 行具有相同ad_id
”,...>db>>小提琴此处
The question leaves room for interpretation. This test case shows 2 nested steps:
How many duplicates per value?
Result:
Read:
ad_id 62
exists 1x,ad_id 288
exists 4x, ...How to count how many times rows have duplicates?
Result:
Read: 8 occurrences of "
ad_id
is unique", 7 occurrences of "2 rows with samead_id
", ...db<>fiddle here
只需将
count(*)
添加到您的选择中即可:Just add
count(*)
to your select: