If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Newbie query question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-09, 11:53
earachefl earachefl is offline
Registered User
 
Join Date: Dec 2009
Posts: 2
Newbie query question

Hi, I'm trying to complete an assignment, and have no clue. There are two similar assignments; if I figure out the one, I'm sure the second will be practically similar.

The first involves two relations. One relation, Facility, has three fields:
Facility_ID (primary key)
Facility_Name
Address

The second relation, Conference_Room, also has three fields:
Room_ID (primary key)
Facility_ID (primary key)
Fee
Foreign key (facility_id) references Facility (facility_id)

The assignment: Create a query that lists the TOTAL number of conference rooms in EACH facility.

I have no problem constructing a query that returns the total for ALL facilities, or for one particular facility, but how do I implement a SUM function on EACH facility and return all those results at once?

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old 12-07-09, 12:27
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
look into the use of GROUP BY clause. Then show us what you've attempted.
Reply With Quote
  #3 (permalink)  
Old 12-07-09, 12:54
earachefl earachefl is offline
Registered User
 
Join Date: Dec 2009
Posts: 2
Ah, I see:

select facility_id, count(room_id)
from conference_room
group by facility_id;

Thanks... my textbook doesn't mention anything about functions or aggregate functions, so am on my own... and the mysql reference manual is not helpful for newbies like me.
Reply With Quote
  #4 (permalink)  
Old 12-07-09, 19:42
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Quote:
Originally Posted by earachefl View Post
my textbook doesn't mention anything about functions or aggregate functions, so am on my own
you need a new textbook.

Quote:
Originally Posted by earachefl View Post
... and the mysql reference manual is not helpful for newbies like me.
take the time to learn the manual, it is very in-depth
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On