Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Unanswered: 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.

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    look into the use of GROUP BY clause. Then show us what you've attempted.

  3. #3
    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.

  4. #4
    Join Date
    Mar 2004
    Posts
    480
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •