我有一个包含状态列的表。我需要编写一个返回记录的查询,其中某些列值出现多次?
这样的事情:
select * from Table1
where COUNT(StatusID = 6) > 1
答案 0 :(得分:1)
您可以编写如下查询:
SELECT *
FROM Table1
WHERE StatusID IN
(
SELECT StatusID
FROM (SELECT StatusID,Count(*) AS cnt FROM Table1 WHERE StatusID=6
GROUP BY StatusID
HAVING COUNT(*) > 1) AS tbl
)