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.
Author |
Topic |
tsaliki
Starting Member
19 Posts |
Posted - 2013-09-19 : 08:10:38
|
i have a table emp with records as follows:empname highprtjobstsaliki h1sasi h2Srinivas h3 tsaliki h4sasi h5in this i wrote a select statement as follows:select empname,count(highprtjobs)as noofhighprtjobs from testemp group by empname. i got the result as empname noofhighprtjobssasi 2srinivas 1tsaliki 2In this now i am trying to get the one which is having min noofhighprtjobs. So i wrote the above statement but it is throwing some error.So how do i get the empname whose noofhighprtjobs is minimum.select empname,count(highprtjobs)as noofhighprtjobs from testemp group by empnamehaving min(count(highprtjobs)) |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-09-19 : 08:19:38
|
select empname,count(highprtjobs)as noofhighprtjobs from testemp group by empname,highprtjobsveeranjaneyulu |
|
|
tsaliki
Starting Member
19 Posts |
Posted - 2013-09-19 : 08:22:13
|
No i want the result of only min one i.e here i want the result set of only srinivas |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-09-19 : 08:41:58
|
[code]select TOP (1) empname,count(highprtjobs)as noofhighprtjobs from testemp group by empnameORDER BY 2;[/code] |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-09-19 : 08:45:14
|
select empname,count(highprtjobs)as noofhighprtjobs from Temp1 group by empnamehaving count(highprtjobs) < 2veeranjaneyulu |
|
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-09-19 : 19:37:40
|
select top 1 with ties emp, count(*) as cntfrom table_namegroup by emporder by cnt asc |
|
|
|
|
|