sql server programming:
I want to be able to count number of rows with values > 75. For example, I have the following statement, select p.PositionID,jobTitle,Qualified=count(screentestscore > 75) from Position p left join applicant a on p.PositionID = a.PositionID group by p.positionID,p.JobTitle This gives me an error on the ">". If I do "count(screentestscrore)", it works fine and gives me number of non-null values. If I have a row with screentestscore = 50 and one with a score of 90, Qualified will be = 2. What I want is to have Qualified = 1. Do I do this with count? Thanks, Tom
select p.PositionID,jobTitle, Count(*) from Position p left join applicant a on p.PositionID = a.PositionID Where screentestscore > 75 group by p.positionID,p.JobTitle -- HTH, Jens Suessmeyer. --- http://www.sqlserver2005.de --- [quoted text, click to view] "tshad" wrote: > I want to be able to count number of rows with values > 75. > > For example, I have the following statement, > > select p.PositionID,jobTitle,Qualified=count(screentestscore > 75) from > Position p left join applicant a on p.PositionID = a.PositionID group by > p.positionID,p.JobTitle > > This gives me an error on the ">". > > If I do "count(screentestscrore)", it works fine and gives me number of > non-null values. > > If I have a row with screentestscore = 50 and one with a score of 90, > Qualified will be = 2. What I want is to have Qualified = 1. > > Do I do this with count? > > Thanks, > > Tom > >
"Jens Süßmeyer" <Jens@[Remove_that][for contacting me]sqlserver2005.de> [quoted text, click to view] wrote in message news:B1CA3D19-D96C-4460-B40C-A2A5F176889C@microsoft.com... > > > select p.PositionID,jobTitle, Count(*) from > Position p left join applicant a on p.PositionID = a.PositionID > Where screentestscore > 75 > group by p.positionID,p.JobTitle
That would work if I was only looking for that variable, but I am looking for 4 or 5 counts from the same same files (should have mentioned that. Here is the statement I had put together. select p.PositionID,jobTitle,Submissions = count(resume),Applications = count(application),Screened=count(screentest),Qualified=count(screentestscor e > 75) from Position p left join applicant a on p.PositionID = a.PositionID group by p.positionID,p.JobTitle Thanks, Tom [quoted text, click to view] > -- > HTH, Jens Suessmeyer. > > --- > http://www.sqlserver2005.de > --- > > > "tshad" wrote: > > > I want to be able to count number of rows with values > 75. > > > > For example, I have the following statement, > > > > select p.PositionID,jobTitle,Qualified=count(screentestscore > 75) from > > Position p left join applicant a on p.PositionID = a.PositionID group by > > p.positionID,p.JobTitle > > > > This gives me an error on the ">". > > > > If I do "count(screentestscrore)", it works fine and gives me number of > > non-null values. > > > > If I have a row with screentestscore = 50 and one with a score of 90, > > Qualified will be = 2. What I want is to have Qualified = 1. > > > > Do I do this with count? > > > > Thanks, > > > > Tom > > > > > >
Hi Try this SELECT <column lists> FROM Table WHERE 75<(SELECT COUNT(*) FROM Table t WHERE t.PK<=Table.PK) [quoted text, click to view] "tshad" <tfs@dslextreme.com> wrote in message news:%23DkDl9ylFHA.2916@TK2MSFTNGP14.phx.gbl... >I want to be able to count number of rows with values > 75. > > For example, I have the following statement, > > select p.PositionID,jobTitle,Qualified=count(screentestscore > 75) from > Position p left join applicant a on p.PositionID = a.PositionID group by > p.positionID,p.JobTitle > > This gives me an error on the ">". > > If I do "count(screentestscrore)", it works fine and gives me number of > non-null values. > > If I have a row with screentestscore = 50 and one with a score of 90, > Qualified will be = 2. What I want is to have Qualified = 1. > > Do I do this with count? > > Thanks, > > Tom > >
[quoted text, click to view] "tshad" <tfs@dslextreme.com> wrote in message news:e3xZpXzlFHA.2904@tk2msftngp13.phx.gbl... > "Jens Süßmeyer" <Jens@[Remove_that][for contacting me]sqlserver2005.de> > wrote in message > news:B1CA3D19-D96C-4460-B40C-A2A5F176889C@microsoft.com... >> >> >> select p.PositionID,jobTitle, Count(*) from >> Position p left join applicant a on p.PositionID = a.PositionID >> Where screentestscore > 75 >> group by p.positionID,p.JobTitle > > That would work if I was only looking for that variable, but I am looking > for 4 or 5 counts from the same same files (should have mentioned that. > > Here is the statement I had put together. > > select p.PositionID,jobTitle,Submissions = count(resume),Applications = > count(application),Screened=count(screentest),Qualified=count(screentestscor > e > 75) from Position p left join applicant a on p.PositionID = > a.PositionID > group by p.positionID,p.JobTitle
In the articles I have seen on Count(), it usually says that the parameter can be either: *, field, expr. What I am trying to do is Count(expr), but I can't seem to find any examples of this. Normally, I would use Count(ScreenTestScore), but I only want ScreenTestScores > 75, so that was why I tried Count(ScreenTestScore > 75), which is apparently not legal. So the question is how to do all the Count's in one statement with 1 or 2 with an expression. Thanks, Tom [quoted text, click to view] > > Thanks, > > Tom >> -- >> HTH, Jens Suessmeyer. >> >> --- >> http://www.sqlserver2005.de >> --- >> >> >> "tshad" wrote: >> >> > I want to be able to count number of rows with values > 75. >> > >> > For example, I have the following statement, >> > >> > select p.PositionID,jobTitle,Qualified=count(screentestscore > 75) from >> > Position p left join applicant a on p.PositionID = a.PositionID group >> > by >> > p.positionID,p.JobTitle >> > >> > This gives me an error on the ">". >> > >> > If I do "count(screentestscrore)", it works fine and gives me number of >> > non-null values. >> > >> > If I have a row with screentestscore = 50 and one with a score of 90, >> > Qualified will be = 2. What I want is to have Qualified = 1. >> > >> > Do I do this with count? >> > >> > Thanks, >> > >> > Tom >> > >> > >> > > >
[quoted text, click to view] "Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message news:ob05f198qsturofng4uq8u60mcgj51nar6@4ax.com... > On Tue, 2 Aug 2005 00:45:26 -0700, tshad wrote: > >>"Jens Süßmeyer" <Jens@[Remove_that][for contacting me]sqlserver2005.de> >>wrote in message >>news:B1CA3D19-D96C-4460-B40C-A2A5F176889C@microsoft.com... >>> >>> >>> select p.PositionID,jobTitle, Count(*) from >>> Position p left join applicant a on p.PositionID = a.PositionID >>> Where screentestscore > 75 >>> group by p.positionID,p.JobTitle >> >>That would work if I was only looking for that variable, but I am looking >>for 4 or 5 counts from the same same files (should have mentioned that. > (snip) > > Hi Tom, > > Try if this gets you what you need: > > SELECT p.PositionID, > p.JobTitle, > COUNT(a.ScreenTest) AS Screened, > COUNT(CASE WHEN a.ScreenTestScore > 75 THEN 1 END) AS > Qualified > FROM Position AS p > LEFT JOIN Applicant AS a > ON a.PPositionID = p.PositionID > GROUP BY p.PositionID, p.JobTitle >
That seemed to do exactly what I wanted. I know that the docs say you can do Count(expr), but I couldn't figure out how to make "ScreenTestScore > 75" into an expression that Count would accept or use. Yours work great (as far as I can tell). Thanks, Tom [quoted text, click to view] > (untested) > > Best, Hugo > -- > > (Remove _NO_ and _SPAM_ to get my e-mail address)
[quoted text, click to view] On Tue, 2 Aug 2005 00:45:26 -0700, tshad wrote: >"Jens Süßmeyer" <Jens@[Remove_that][for contacting me]sqlserver2005.de> >wrote in message news:B1CA3D19-D96C-4460-B40C-A2A5F176889C@microsoft.com... >> >> >> select p.PositionID,jobTitle, Count(*) from >> Position p left join applicant a on p.PositionID = a.PositionID >> Where screentestscore > 75 >> group by p.positionID,p.JobTitle > >That would work if I was only looking for that variable, but I am looking >for 4 or 5 counts from the same same files (should have mentioned that.
(snip) Hi Tom, Try if this gets you what you need: SELECT p.PositionID, p.JobTitle, COUNT(a.ScreenTest) AS Screened, COUNT(CASE WHEN a.ScreenTestScore > 75 THEN 1 END) AS Qualified FROM Position AS p LEFT JOIN Applicant AS a ON a.PPositionID = p.PositionID GROUP BY p.PositionID, p.JobTitle (untested) Best, Hugo --
Don't see what you're looking for? Try a search.
|