0

我已经想太多了。假设我有一个表 TEST(refnum VARCHAR(5))

    |refnum|
    --------
    | 12345|
    | 56873|
    | 63423|
    | 12345|
    | 56873|
    | 12345|

我希望我的“观点”看起来像这样

    |refnum| count|
    ---------------
    | 12345|   3  |
    | 56873|   2  |

因此,要求是每个引用句柄的计数必须 > 1。我在解决这个问题时遇到了一些麻烦。预先感谢您的帮助。

4

3 回答 3

11

除非我遗漏了什么,否则这看起来很简单

select refnum, count(*) from test group by refnum having count(*) > 1
于 2013-05-22T00:48:00.940 回答
0
select refnum, count(*)
from table
group by refnum
于 2013-05-22T00:48:59.427 回答
0

这是 SQL Server 版本:

CREATE VIEW vRefnumCounts AS
SELECT refnum, 
count(1) as [count] 
FROM test 
GROUP BY refnum 
HAVING count(1) > 1

SELECT *
FROM vRefnumCounts 
ORDER BY refnum

您说的是“视图”,但现在我认为您的意思是结果集意义上的......

于 2013-05-22T01:22:25.893 回答