Question

create table Buildings ( integer, varchar (100), varchar (100), varchar (2), 2 id unswid 4 name 5 campus primary key (id) 6 8

If I have this schema, how can I solve the following problem by using MySQL? Please help me, thanks a lot.

3. (2 Marks) Find the id and name of the rooms with maximum capacity for each building at campus K Ignore the buildings with

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Find the id and name of the rooms with maximum capacity for each building at campus "K"

select r.id , r.name from Rooms r,
(select r.building building, max(r.capacity) max_cap from Rooms r, Buildings b where r.building = b.id and b.campus = 'K' group by r.building) mcb
where r.building = mcb.building and r.capacity = mcp.max_cap;

The inner query returns the id and capacity of the maximum capacity building in campus "K" by joining the Rooms and Buildings tables on field building id. The outer query returns the id and name of the rooms with the maximum capacity present in each building.

Add a comment
Know the answer?
Add Answer to:
If I have this schema, how can I solve the following problem by using MySQL? Please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using MySQL, you will create data base for given conditions and examine the mysqldump. •Create t...

    Using MySQL, you will create data base for given conditions and examine the mysqldump. •Create the table for the given data structure PASSENGERS: passengerid INTEGER, name VARCHAR(30), surname VARCHAR(30), email VARCHAR(50), address VARCHAR(100), city VARCHAR(30) FLT-SCHEDULE: fltno INTEGER, airlinename VARCHAR(50), dtime TIME, from-airportcode VARCHAR(5), atime TIME, to-airportcode VARCHAR(5), miles INTEGER, price INTEGER FLT-HISTORY: passengerid INTEGER, airlineid INTEGER, fltdate DATE AIRLINE: airlineid INTEGER, airlinename VARCHAR(50) -Conditions- For each passengers passengerid is neccessary (primary key). Name, surname, address information, city information, e-mail...

  • Using MySQL commands answer the questions listed below using the Premier Products Company schema. 1.Using Views...

    Using MySQL commands answer the questions listed below using the Premier Products Company schema. 1.Using Views a) Create a view called part_location that has the following attributes: part_num, part_description, part_quantity, warehouse_name, warehouse_address. This data comes from the part and warehouse entities. b) Write a query using the view that shows the total number of parts ordered from each warehouse. The output should look like this: 2. Using Triggers a) Execute the following SQL to create the customer_audit table in the...

  • Database concepts Find the names and ids of the students who have taken at most one...

    Database concepts Find the names and ids of the students who have taken at most one course in the Spring 2010 semester. Notice, at most one means one or zero. So, the answer should include students who did not take any course during that semester The data: create table classroom     (building       varchar(15),      room_number        varchar(7),      capacity       numeric(4,0),      primary key (building, room_number)     ); create table department     (dept_name      varchar(20),      building       varchar(15),      budget      numeric(12,2) check (budget > 0),      primary key (dept_name)     ); create...

  • This is database system concept. 1.Find the ids of instructors who are also students using a...

    This is database system concept. 1.Find the ids of instructors who are also students using a set operation. Assume that a person is identified by her or his id. So, if the same id appears in both instructor and student, then that person is both an instructor and a student. Remember: set operation means union, intersect or set difference. 2.Find the ids of instructors who are also students using the set membership operator. 3.Find the ids of instructors who are...

  • Given the schema, write a query and subquery to do the following: CREATE TABLE Majors major...

    Given the schema, write a query and subquery to do the following: CREATE TABLE Majors major VARCHAR(12), description VARCHAR, PRIMARY KEY (major) ); CREATE TABLE Course ( courseMajor VARCHAR(12), courseNo VARCHAR(6), credits INTEGER NOT NULL, enroll_limit INTEGER, PRIMARY KEY(courseNo, courseMajor), FOREIGN KEY (courseMajor) REFERENCES Majors (major) CREATE TABLE Tracks trackMajor VARCHAR(12), trackCode VARCHAR(10), title VARCHAR, PRIMARY KEY(trackMajor, trackCode), FOREIGN KEY (trackMajor) REFERENCES Majors(major) CREATE TABLE Student ( SID CHAR(8), sName VARCHAR(30), studentMajor VARCHAR(12), trackCode VARCHAR(10), PRIMARY KEY(SID), FOREIGN KEY (studentMajor,...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

  • I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descr...

    I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descriptions of the customers who submitted no orders. For example, these are the customers who registered themselves and submitted no orders so far. The granted privilege cannot be propagated to the other users. 0.3 (14)Next, grant to a user admin the read privileges on information about the total number of orders submitted by each customer. Note, that some customers...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • 4 Consider the following relational schema, DDL statements and tables: EMPLOYEE( EmployeeID, EmployeeName, SupervisorID, DepartmentID) PROJECT...

    4 Consider the following relational schema, DDL statements and tables: EMPLOYEE( EmployeeID, EmployeeName, SupervisorID, DepartmentID) PROJECT (ProjectID, EmployeeID) DEPARTMENT( Department ID, DepartmentName) CREATE TABLE EMPLOYEE ( EmployeeID          INT           PRIMARY KEY,    EmployeeName   VARCHAR(50)      NOT NULL,    SupervisorID INT DEFAULT 9,    DepartmentID   INT,    FOREIGN KEY (SupervisorID) REFERENCES EMPLOYEE (EmployeeID)    ON DELETE SET DEFAULT   ),    FOREIGN KEY (DepartmentID) REFERENCES DEPARTMENT(DepartmentID)    ON UPDATE SET NULL); CREATE TABLE PROJECT ( ProjectID    INT          PRIMARY KEY, EmployeeID INT DEFAULT 9, FOREIGN...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT