Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Nudge me on "Count"

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-10 : 13:21:10
I need to show all rows in a table where the same EVPNO occurs more than three times. right now, i have Select * from evp_coc order by evpno.

But i only want to show those instances where the EVPNO is repeated more than three times.

I know it's simple, but i'm mind numbed right now.

thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 13:23:55
[code]
select required columns...
from
(
Select *,count(1) over (partition by evpno) as cnt
from evp_coc
)t
where Cnt >3
order by evpno
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-10 : 13:24:56
ok, so it wasn't as simple as i thought. Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 13:27:08
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-10 : 13:40:48
SELECT EVPNO, COUNT(*)
FROM yourTable99
GROUP BY EVPNO
HAVING COUNT(*) > 3

Can we please start with the basics?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -