Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SubQuery Count

Status
Not open for further replies.

IAMINFO

MIS
Feb 21, 2002
62
US
Hello everyone please help if you can, I am trying to write a query that shows me every cell in a housing area that has 3 inmates , when I run what I have written I see cells with 2 and 3 inmates. Please advise

Thank you for helping.

select offender, facility,block,cell,bed,movein,moveout,stay

from pps_housingchanges AS H


WHERE ((Select count(*)AS Expr1
from pps_housingchanges AS H1
where (H.block = block) and (H.cell = cell))>2) and facility='THC' and moveout is null
order by block,cell
 
select offender, facility,block,cell,bed,movein,moveout,stay
from pps_housingchanges AS H
inner join (Select count(*)AS Expr1,block,cell
from pps_housingchanges
Where facility='THC' and moveout is null
Group by block,cell
having count(*)>2)hi
on h1.cell=h.cell
and h1.block=h.block
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top