展开 GROUP BY 和 HAVING 结果集

发布于 2024-12-01 04:25:12 字数 515 浏览 1 评论 0原文

有没有办法扩展/获取 GROUP BY 和 HAVING 查询的所有记录?

例如,

SELECT Column1, Column2, Column3, Count(*) as Count FROM table_name
GROUP BY Column1, Column2, Column3
HAVING Count > '2'

是否有一种更简单的方法来获取所有记录,而不是遍历结果集并执行 SELECT * FROM table_name WHERE Column1 = 'this' AND Column2 = 'that' AND Column3 = 'more' 对于每条记录。

如果由于mysql或其他一些限制而无法完成,是否有其他方法可以获取上面查询的所有数据?

通过展开/获取所有记录,我的意思是如果结果集是

Value1 Value2 Value3 4

我希望能够获取所有 4 条记录。

Is there a way to expand/get all the records of a GROUP BY and HAVING query?

For example,

SELECT Column1, Column2, Column3, Count(*) as Count FROM table_name
GROUP BY Column1, Column2, Column3
HAVING Count > '2'

Is there an easier way to get all the records rather than going through the result set and doing SELECT * FROM table_name WHERE Column1 = 'this' AND Column2 = 'that' AND Column3 = 'more' for each record.

If it cannot be done due to mysql or some other restrictions is there any other way to get all the data for query above?

By expand/get all the records, I mean if the result set is

Value1 Value2 Value3 4

I want to be able to get all the 4 records.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-12-08 04:25:12

您的意思是这样的吗:

SELECT a.*, b.Count
FROM table_name AS a
INNER JOIN (
    SELECT Column1, Column2, Column3, Count(*) as Count FROM table_name
    GROUP BY Column1, Column2, Column3
    HAVING Count > '2'
) b
ON a.Column1 = b.Column1 AND a.Column2 = b.Column2 AND a.Column3 = b.Column3

这基本上是您在问题中描述的内容,但在 JOIN 中。

Do you mean something like this:

SELECT a.*, b.Count
FROM table_name AS a
INNER JOIN (
    SELECT Column1, Column2, Column3, Count(*) as Count FROM table_name
    GROUP BY Column1, Column2, Column3
    HAVING Count > '2'
) b
ON a.Column1 = b.Column1 AND a.Column2 = b.Column2 AND a.Column3 = b.Column3

This is basically what you described in your question but in a JOIN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文