Question

In: Computer Science

Please write queries based on the following requirements using DML In-Class Data Set. For each question,...

Please write queries based on the following requirements using DML In-Class Data Set. For each question, you are required to submit 1) SQL query code; 2) a screen shot of your query result.You should copy and paste your SQL query code to the word document instead of taking a screenshot of your code. Missing either part for each question will result in 0 for this question.

8.List the warehouse number and the average unit price for warehouses other than number 2.

9.List the stored part information for SG parts stored in warehouse 2 or 3.

10.List the part number and part description for each part with letter D(or d) in the part_description. Rank your results in ascending order on itemclass and then descending order on units_on_hand.

11.List the average unit price among all the parts. Rename the column as AVG_UNIT_PRICE

12.List the part number and part description for each part with nine characters or ten characters in the part_description. Rank your results in ascending order on part number.

13.Find the itemclasses and the number of parts under each class. Only show those classes with at least3 types of parts.

14.List the stored part information for SG parts or parts with more than 60 units stored in warehouse 3.

15.List the number of different part stored in each warehouse, only include those warehouse with at most3parts.

Solutions

Expert Solution

8.

SELECT WAREHOUSE_NUMBER,

AVG(UNIT_PRICE)

FROM PART

WHERE NOT WAREHOUSE_NUMBER=2

GROUP BY WAREHOUSE_NUMBER;

9.

SELECT * FROM PART

WHERE WAREHOUSE_NUMBER IN(2,3)

AND ITEM_CLASS= 'SG';

10.

SELECT PART_NUMBER, PART_DESCRIPTION

FROM PART

WHERE PART_DESCRIPTION LIKE '%D%'

ORDER BY ITEM_CLASS ASC,

UNITS_ON_HAND DESC;

EXPLANATION:

PART_DESCRIPTION LIKE '%D%'

Means that Those part numbers and description will be printed where part_description contains character 'D' or 'd' at any position.

11.

SELECT PART_NUMBER,

AVG(UNIT_PRICE) AS "AVG_UNIT_PRICE"

FROM PART

GROUP BY PART_NUMBER;

12.

SELECT PART_NUMBER, PART_DESCRIPTION

FROM PART

WHERE PART_DESCRIPTION LIKE '_________' OR '__________'

ORDER BY PART_NUMBER;

EXPLANATION:

To select part numbers where part_description is 9 or 10 characters long, we use LIKE operator:

LIKE PART_DESCRIPTION '_________' OR '__________'

i.e.,

9 times underscore OR 10 times underscore.

No. Of Underscores denotes the number of characters.

13.

SELECT ITEM_CLASS, COUNT(PART_NUMBER) AS "No. Of Parts"

FROM PART

GROUP BY ITEM_CLASS

HAVING "No. Of Parts" >= 3;


Related Solutions

Please write queries based on the following requirements using labdata.sql. For each question, you are required...
Please write queries based on the following requirements using labdata.sql. For each question, you are required to submit 1) SQL query code; 2) a screen shot of your query result. You should copy and paste your SQL query code to the word document instead of taking a screenshot of your code. Missing either part for each question will result in 0 for this question. List all the order date and the number of orders placed on each date. Rank your...
Problems Please write queries based on the following requirements using labdata.sql or premieresetupmysql.sql. For each question,...
Problems Please write queries based on the following requirements using labdata.sql or premieresetupmysql.sql. For each question, you are required to submit 1) SQL query code; 2) a screen shot of your query result. You should copy and paste your SQL query code to the word document instead of taking a screenshot of your code. Missing either part for each question will result in 0 for this question. List unique item classes stored in my database. List the warehouse number and...
Question 1 – Inserting data to the CITY table Using the following DML statement: INSERT INTO...
Question 1 – Inserting data to the CITY table Using the following DML statement: INSERT INTO CITY (id, name, countrycode, district, population) VALUES (7000, ‘Guelph’, ‘CAN’, ‘Ontario’, 131794); Query the CITY table to ensure this row was inserted correctly. Provide screenshot of your ‘SELECT statement’ and resultset pane here                Insert another row into the CITY table with the following values:                               Id                           7002                               Name                   Montebello                               Countrycode       CAN                               District                 Quebec                               Population          983 Provide screenshot...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName,...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName, LastName, Year) Takes (Username, Department, Number, Term, Grade) [clarification] In Student, Year is an integer. A student can be a 2nd year student. In that case, Year value would be 2. For the Takes relation: ·         Grade is NA for current semester students ·         Username is foreign key to Student ·         (Department, Number, Term) is foreign key to Class a)       Write an SQL query that returns the Term...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName,...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName, LastName, Year) Takes (Username, Department, Number, Term, Grade) [clarification] In Student, Year is an integer. A student can be a 2nd year student. In that case, Year value would be 2. For the Takes relation: ·         Grade is NA for current semester students ·         Username is foreign key to Student ·         (Department, Number, Term) is foreign key to Class a)       Write an SQL query that returns the Term...
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
) Write queries for the following. Include screenshots of the queries and the outputs. Create a...
) Write queries for the following. Include screenshots of the queries and the outputs. Create a procedure named DisplayInfo which takes customer name as a parameter and displays information of that customer. (database – sql_store)
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT