Question

In: Computer Science

A. Project 1 case: DDL’s and Business Rules - The SQL queries for this project are...

A. Project 1 case: DDL’s and Business Rules - The SQL queries for this project are based on the business rules from PROJECT 1. Thus, the SQL queries will run against the tables from Project 1 (see section B below). The following is a list of the business rules derived from the Project 1 assignment:

- A university is identified by its name and located in a particular city.

- A university has many researchers, each of whom can only be associated with only one university.

- A researcher is identified by an identification number, and has a name, phone, and email address.

- A researcher can attend many conferences.

- A conference is identified by an identification number; it also has a name, a location, and a date.

- For each conference, a researcher may or may not present a scientific research paper.

- For each conference, one university is in-charge of its logistic, while another university is in-charge of its marketing.

- A university can be involved in either role with any conference.

B. Run the following DDL’s and add your own data rows to the tables

CREATE TABLE `university` (

`UNIVERSITY_ID` int(11) NOT NULL,

`UNIVERSITY_NAME` varchar(45) DEFAULT NULL,

`UNIVERSITY_CITY` varchar(45) DEFAULT NULL,

`UNIVERSITY_STATE` varchar(2) DEFAULT NULL,

PRIMARY KEY (`UNIVERSITY_ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `conference` (

`CONFERENCE_ID` int(11) NOT NULL,

`CONFERENCE_NAME` varchar(45) DEFAULT NULL,

`CONFERENCE_CITY` varchar(45) DEFAULT NULL,

`CONFERENCE_DATE` date DEFAULT NULL,

`UNIVERSITY_ID_LOGISTICS` int(11) NOT NULL,

`UNIVERSITY_ID_MARKETING` int(11) NOT NULL,

`CONFERENCE_STATE` varchar(2) DEFAULT NULL,

PRIMARY KEY (`CONFERENCE_ID`,`UNIVERSITY_ID_LOGISTICS`,`UNIVERSITY_ID_MARKETING`),

KEY `fk_CONFERENCE_UNIVERSITY1_idx` (`UNIVERSITY_ID_LOGISTICS`),

KEY `fk_CONFERENCE_UNIVERSITY2_idx` (`UNIVERSITY_ID_MARKETING`),

CONSTRAINT `fk_CONFERENCE_UNIVERSITY1` FOREIGN KEY (`UNIVERSITY_ID_LOGISTICS`) REFERENCES `university` (`UNIVERSITY_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,

CONSTRAINT `fk_CONFERENCE_UNIVERSITY2` FOREIGN KEY (`UNIVERSITY_ID_MARKETING`) REFERENCES `university` (`UNIVERSITY_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `researcher` (

`researcher_id` int(11) NOT NULL,

`res_lname` varchar(45) DEFAULT NULL,

`res_fname` varchar(45) DEFAULT NULL,

`res_title` varchar(45) DEFAULT NULL,

`university_UNIVERSITY_ID` int(11) NOT NULL,

PRIMARY KEY (`researcher_id`,`university_UNIVERSITY_ID`),

KEY `fk_researcher_university1_idx` (`university_UNIVERSITY_ID`),

CONSTRAINT `fk_researcher_university1` FOREIGN KEY (`university_UNIVERSITY_ID`) REFERENCES `university` (`UNIVERSITY_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `conference_has_researcher` (

`CONFERENCE_CONFERENCE_ID` int(11) NOT NULL,

`RESEARCHER_RESEARCHER_ID` int(11) NOT NULL,

PRIMARY KEY (`CONFERENCE_CONFERENCE_ID`,`RESEARCHER_RESEARCHER_ID`),

KEY `fk_CONFERENCE_has_RESEARCHER_RESEARCHER1_idx` (`RESEARCHER_RESEARCHER_ID`),

KEY `fk_CONFERENCE_has_RESEARCHER_CONFERENCE_idx` (`CONFERENCE_CONFERENCE_ID`),

CONSTRAINT `fk_CONFERENCE_has_RESEARCHER_CONFERENCE` FOREIGN KEY (`CONFERENCE_CONFERENCE_ID`) REFERENCES `conference` (`CONFERENCE_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,

CONSTRAINT `fk_CONFERENCE_has_RESEARCHER_RESEARCHER1` FOREIGN KEY (`RESEARCHER_RESEARCHER_ID`) REFERENCES `researcher` (`researcher_id`) ON DELETE NO ACTION ON UPDATE NO ACTION

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

C. Data Queries   “Good questions to ask of your data” – The business rules from section A above were used to derive the following 10 query descriptions below. Read each description and write the equivalent SQL query.

1. List the universities sorted by city.

2. List the Researchers sorted by last name.

3. List the researchers and their corresponding universities sorted by the university city. You must use an INNER JOIN with RESEARCHER and UNIVERSITY tables.

4. List the university and “count” of researchers at each university sorted by the university name.

You CANNOT use an inner join. You must use a subquery with RESEARCHER.

5. List the university and “count” of researchers at each university where there is more than 1 researcher. Also, sort this query by the university name. You must user an INNER JOIN (NOT A SUBQUERY)

6. List all conferences in the state of georgia. Include the city and state with the query.

7. List the conference and researcher count for conferences in georgia. You CANNOT use an inner join. You must use “two” subqueries that are nested.

8. List the researcher, university and conferences where the conference is in California. You must user an INNER JOIN (NOT A SUBQUERY).

9. List the university and count of researchers that are planning to present at a conference in 2021. You CANNOT use an inner join. You must use a subquery.

10. List the Universities in the database table. If the university appears in a conference that is in charge of its marketing. Each university can only be listed once. You must user an OUTER JOIN (NO INNER JOIN OR SUBQUERY).

I have part A completed. I am stuck on part C mostly, but help on part B would be greatly appreciated.

Solutions

Expert Solution

1. List the universities sorted by city :

select UNIVERSITY_NAME from university order by UNIVERSITY_CITY;

  • This SQL query is using order by clause to order the records

******************************************

2. List the Researchers sorted by last name :

select concat(res_fname,' ',res_lname) as 'researcher name' from researcher
order by res_lname;

  • This SQL query is using concat() function along with order by clause

*******************************************

3. List the researchers and their corresponding universities sorted by the university city. You must use an INNER JOIN with RESEARCHER and UNIVERSITY tables.

select concat(res_fname,' ',res_lname) as 'researcher name',UNIVERSITY_NAME
from researcher inner join university
on researcher.university_UNIVERSITY_ID=university.UNIVERSITY_ID
order by UNIVERSITY_CITY;

  • This SQL query join two tables researcher and university based on UNIVERSITY_ID and will return the result.

***********************************

4. List the university and “count” of researchers at each university sorted by the university name.

select UNIVERSITY_NAME ,
(select count(researcher_id) from researcher order by university_UNIVERSITY_ID)
as 'Number of researcher' from university
order by UNIVERSITY_NAME;

  • This SQL query is using sub query to get the result.

********************************************

5. List the university and “count” of researchers at each university where there is more than 1 researcher.

select UNIVERSITY_NAME , count(researcher_id) as 'Number of researcher'
from university inner join researcher
on university.UNIVERSITY_ID=researcher.university_UNIVERSITY_ID
group by UNIVERSITY_NAME
having count(researcher_id) >1;

  • This SQL query is grouping the records based on UNIVERSITY_NAME
  • This SQL query is also using having clause

*****************************************

6. List all conferences in the state of georgia:

select CONFERENCE_NAME,CONFERENCE_CITY,CONFERENCE_STATE from conference
where CONFERENCE_STATE like 'georgia';

  • This SQL query using like clause to get CONFERENCE details

*********************************

7. List the conference and researcher count for conferences in georgia.

select CONFERENCE_NAME,
(select count(RESEARCHER_RESEARCHER_ID) from conference_has_researcher
where CONFERENCE_CONFERENCE_ID in (select CONFERENCE_ID from conference
where CONFERENCE_STATE like 'georgia')) as 'Number of researchers' from conference;

  • This SQL query is using subquery to get the result.

************************************


Related Solutions

Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an SQL statement to display all the information of all Nobel Laureate winners. 2) Write an SQL statement to display the string "Hello, World!". 3) Write an SQL query to display the result of the following expression: 2 * 14 +76. 4) Write an SQL statement to display the winner and category of all Laureate winners. 5) Write an SQL query to find the winner(s)...
I am having a hard time writing these SQL queries. Please specify the following queries in...
I am having a hard time writing these SQL queries. Please specify the following queries in SQL on the database schema shown in the figure below. STUDENT Name StudentNumber Class Major Smith 17 1 CS Brown 8 2 CS Kathy 15 1 EE COURSE CourseName CourseNumber CreditHours Department Intro to Computer Science CSE110 4 CS Data Structures CSE205 4 CS Discrete Mathematics MAT240 3 MATH Databases CSE380 3 CS Analog Circuits EE260 3 EE SECTION SectionIdentifier CourseNumber Semester Year Instructor...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in the WPC Database in MySQL: Display all records from the Employee table for employees working in the “Marketing” department. Display all records from the Employee table for employees working in the “Marketing” department OR “Finance” Department. Display the Last Names of all employees such that each last name appears only once. Display all the attributes for employees whose employee number is less than 10....
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least three rows in each table. For the On-Demand Streaming System, First, insert information for multiple users, at least three video items and insert the three different types of subscriptions (Basic, Advanced, Unlimited) into the database. Then insert at least three user subscriptions. Execute the queries and make sure they run correctly
Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save...
Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save your file as Comp2138LabTest1_JohnSmith100123456.sql (replace JohnSmith 100123456 with your name and student ID). Please place comment that includes your name and your student ID at the top of your script and number your queries using comments sections. Each query carries equal weight. A selection of the expected result set has been shown below for your convenience. Your output should match with this sample output....
What are the keywords available in MS Access to use in SQL queries to enforce these...
What are the keywords available in MS Access to use in SQL queries to enforce these data integrity constraints? Discuss these with proper SQL queries.
In this assignment, you are required to write the SQL statements to answer the following queries...
In this assignment, you are required to write the SQL statements to answer the following queries using PostgreSQL system. The SQL statements comprising the DDL for Henry Books Database are given to you in two files. For that database, answer the following queries. Create the files Q1 to Q10 in PostgreSQL. Do follow the restrictions stated for individual queries. 1. List the title of each book published by Penguin USA. You are allowed to use only 1 table in any...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
Does the data contain errors? If so, write queries in SQL to find these errors and...
Does the data contain errors? If so, write queries in SQL to find these errors and propose a way to address the issues Theres a change of weight error (end weight-start weight) calculated wrong and a logical error
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT