Jump to content

SQL subquery counting


nadeemshafi9

Recommended Posts

Hi guys, i am looking for a way using sql whith a subquery to count the amount of properties(pno) each staff member (sno) looks after using 1 table.

here is the schema for the 1 table im talkin about.

property_for_rent (pno, street, area, city, pcode, type, rooms, ono, sno, bno)
PK pno
FK sno
FK bno
FK ono

so i would like to dispplay the sno (sttaff number) along whith the amount (count) of pno (property numbers) that particular staff is repeated in.

i uunderstand count and subqueries, but just cant seem to crack this one.

THANKS FOR NE HELP
Link to comment
Share on other sites

[!--quoteo(post=358574:date=Mar 26 2006, 01:02 PM:name=nadeemshafi9)--][div class=\'quotetop\']QUOTE(nadeemshafi9 @ Mar 26 2006, 01:02 PM) [snapback]358574[/snapback][/div][div class=\'quotemain\'][!--quotec--]
property_for_rent (pno, street, area, city, pcode, type, rooms, ono, sno, bno)
PK pno
FK sno
FK bno
FK ono

so i would like to dispplay the sno (sttaff number) along whith the amount (count) of pno (property numbers) that particular staff is repeated in.

[/quote]

Was there any reason that this wouldn't work?
[code]
SELECT COUNT(*) AS numproperties, sno FROM property_for_rent GROUP BY sno ORDER BY numproperties
[/code]


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.