Reputation: 583
I've been over-thinking this too much. Let's say I have a table TEST(refnum VARCHAR(5))
|refnum|
--------
| 12345|
| 56873|
| 63423|
| 12345|
| 56873|
| 12345|
I want my "view" to look something along the lines of this
|refnum| count|
---------------
| 12345| 3 |
| 56873| 2 |
So the requirements are that the count for each refnum has to be > 1. I'm having a little trouble wrapping my head around this one. Thank you in advance for the help.
Upvotes: 0
Views: 91
Reputation: 10013
This is the SQL Server version:
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
You said "view", but now I'm thinking you meant in the result set sense...
Upvotes: 0
Reputation: 262474
Unless I am missing something, this looks like a simple
select refnum, count(*) from test group by refnum having count(*) > 1
Upvotes: 11