gpt4 book ai didi

sql - 如何获得不明显的值(计数> 1)

转载 作者:行者123 更新时间:2023-12-02 22:29:50 24 4
gpt4 key购买 nike

我正在尝试(在 SQL Server 2k8 中)获取 TheField 的列表,其中 TheField 存在不止一次。类似于以下内容(除非我知道这是不对的):

SELECT TheField FROM TheTable WHERE COUNT(TheField) > 1

最佳答案

您可以使用 GROUP BYHAVING子句:

SELECT TheField, COUNT(*) AS Count
FROM TheTable
GROUP BY TheField
HAVING COUNT(*) > 1

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

关于sql - 如何获得不明显的值(计数> 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12468480/

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