如何计算SQL查询中的行,alredy使用count,group by和having? [英] How do you count the rows in a SQL query which alredy used count, group by, and having before?

查看:219
本文介绍了如何计算SQL查询中的行,alredy使用count,group by和having?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,使用此问题的答案:

For example, using the answer for this question:

如何选择所有提交超过10次提交的用户
如何选择提交超过10次的所有用户。

How to select all users who made more than 10 submissions "How to select all users who made more than 10 submissions."

select userId
from submission   
group by userId
having count(submissionGuid) > 10

现在我想知道这个sql语句输出的多行。

Let's say now I want to know many rows this sql statement outputted. How scalable is the solution for counting the rows of counting the rows?

推荐答案

之前发布的示例中的轻微错误,需要一个别名子查询的表名:

Slight error in previously posted example, need an alias for a table name for the subquery:


select count(*) from
  (select userId
   from submission 
   group by userId
   having count(submissionGuid) > 10) t


b $ b

我不确定可伸缩性,但这是解决方案。如果这不足以满足您的需要,您需要考虑主要的设计更改,例如跟踪那些在单独的表中提交了超过10个提交,您通过填充提交的应用程序更新。或许多其他可能的解决方案。

I'm not sure about scalability, but this is the solution. If this isn't scaling well enough for you, you need to consider major design changes, like perhaps tracking those who submitted more than 10 submissions in a separate table that you update through applications that populate the submissions. Or many other possible solutions.

这篇关于如何计算SQL查询中的行,alredy使用count,group by和having?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆