Question

In: Computer Science

Database questions: USE THE FOLLOWING SQL CODE TO SOLVE NEXT QUESTIONS: CREATE TABLE ROBOT ( Serial_no...

Database questions:
USE THE FOLLOWING SQL CODE TO SOLVE NEXT QUESTIONS:
CREATE TABLE ROBOT
(
Serial_no INT NOT NULL,
Model VARCHAR(20) NOT NULL,
Manufacturer VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_no)
);
INSERT INTO ROBOT VALUES (1, 'Scara','Epson', 23200);
INSERT INTO ROBOT VALUES (2, 'ASSISTA','Mitsubishi', 17500);
INSERT INTO ROBOT VALUES (3, 'Lego Mindstorm','NXT', 650);
INSERT INTO ROBOT VALUES (4, 'Yumi','ABB', 40000);
INSERT INTO ROBOT VALUES (5, 'Pepper','Foxconn', 1600);
INSERT INTO ROBOT VALUES (6, 'Humanoid','Honda', 30000);
SELECT * FROM ROBOT ;
/*===================================================*/
CREATE TABLE OPTIONS
(
Serial_Num INT NOT NULL,
Option_name VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_num, Option_name),
FOREIGN KEY (Serial_num) REFERENCES ROBOT(Serial_no)
);
INSERT INTO OPTIONS VALUES (1, 'Self power', 10000);
INSERT INTO OPTIONS VALUES (1, 'Sense surrounding', 20000);
INSERT INTO OPTIONS VALUES (5, 'Extra Speed', 30000);
INSERT INTO OPTIONS VALUES (2, 'Self power', 40000);
INSERT INTO OPTIONS VALUES (3, 'Motion Balance', 50000);
INSERT INTO OPTIONS VALUES (4, 'Custom look', 60000);
SELECT * FROM OPTIONS;
/*===================================================*/
CREATE TABLE SALESPERSON
(
Salesperson_id INT NOT NULL,
SName VARCHAR(20) NOT NULL,
Phone VARCHAR(20) NOT NULL,
PRIMARY KEY (Salesperson_id)
);
INSERT INTO SALESPERSON VALUES (111, 'Jameco Electronics', '0252354565');
INSERT INTO SALESPERSON VALUES (222,'RobotShop', '0231236455');
INSERT INTO SALESPERSON VALUES (333,'RoboRealm', '0287678790');
SELECT * FROM SALESPERSON ;
/*===================================================*/​
CREATE TABLE SALE
(
Salesperson_id INT NOT NULL,
Serial_no INT NOT NULL,
MyDate DATE NOT NULL,
Sale_Price INT NOT NULL,
PRIMARY KEY (Salesperson_id, Serial_no),
FOREIGN KEY (Salesperson_id) REFERENCES SALESPERSON (Salesperson_id),
FOREIGN KEY (Serial_no) REFERENCES ROBOT(Serial_no)
);
INSERT INTO SALE VALUES (111, 1, DATE'2018-9-23', 22000);
INSERT INTO SALE VALUES (222, 1, DATE'2019-9-22', 21400);
INSERT INTO SALE VALUES (111, 4, DATE'2017-7-21', 37000);
INSERT INTO SALE VALUES (333, 3, DATE'2020-6-14', 470);
SELECT * FROM SALE ;


Q1: Write a query to display all serial numbers of robots that don’t have sales using complex queries

Q2: Write a query that displays the sales price and dynamically assign a deal category to it as follows:
- If the sales price less than or equal 10,000 à accepted-deal price
- If the sales price ranges between 20,000 and 25,000 à average-deal price
- If the sales price greater than 50,000 à rejected-deal price


Solutions

Expert Solution

CREATE DATABASE ROBOTDB;

USE ROBOTDB;

CREATE TABLE ROBOT(
Serial_no INT NOT NULL,
Model VARCHAR(20) NOT NULL,
Manufacturer VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_no)
);

INSERT INTO ROBOT VALUES (1, 'Scara','Epson', 23200);
INSERT INTO ROBOT VALUES (2, 'ASSISTA','Mitsubishi', 17500);
INSERT INTO ROBOT VALUES (3, 'Lego Mindstorm','NXT', 650);
INSERT INTO ROBOT VALUES (4, 'Yumi','ABB', 40000);
INSERT INTO ROBOT VALUES (5, 'Pepper','Foxconn', 1600);
INSERT INTO ROBOT VALUES (6, 'Humanoid','Honda', 30000);
SELECT * FROM ROBOT ;

/*===================================================*/
CREATE TABLE OPTIONS
(
Serial_Num INT NOT NULL,
Option_name VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_num, Option_name),
FOREIGN KEY (Serial_num) REFERENCES ROBOT(Serial_no)
);

INSERT INTO OPTIONS VALUES (1, 'Self power', 10000);
INSERT INTO OPTIONS VALUES (1, 'Sense surrounding', 20000);
INSERT INTO OPTIONS VALUES (5, 'Extra Speed', 30000);
INSERT INTO OPTIONS VALUES (2, 'Self power', 40000);
INSERT INTO OPTIONS VALUES (3, 'Motion Balance', 50000);
INSERT INTO OPTIONS VALUES (4, 'Custom look', 60000);
SELECT * FROM OPTIONS;

/*===================================================*/
CREATE TABLE SALESPERSON
(
Salesperson_id INT NOT NULL,
SName VARCHAR(20) NOT NULL,
Phone VARCHAR(20) NOT NULL,
PRIMARY KEY (Salesperson_id)
);

INSERT INTO SALESPERSON VALUES (111, 'Jameco Electronics', '0252354565');
INSERT INTO SALESPERSON VALUES (222,'RobotShop', '0231236455');
INSERT INTO SALESPERSON VALUES (333,'RoboRealm', '0287678790');
SELECT * FROM SALESPERSON ;

/*===================================================*/​
CREATE TABLE SALE
(
Salesperson_id INT NOT NULL,
Serial_no INT NOT NULL,
MyDate DATE NOT NULL,
Sale_Price INT NOT NULL,
PRIMARY KEY (Salesperson_id, Serial_no),
FOREIGN KEY (Salesperson_id) REFERENCES SALESPERSON (Salesperson_id),
FOREIGN KEY (Serial_no) REFERENCES ROBOT(Serial_no)
);

INSERT INTO SALE VALUES (111, 1, DATE'2018-9-23', 22000);
INSERT INTO SALE VALUES (222, 1, DATE'2019-9-22', 21400);
INSERT INTO SALE VALUES (111, 4, DATE'2017-7-21', 37000);
INSERT INTO SALE VALUES (333, 3, DATE'2020-6-14', 470);
SELECT * FROM SALE ;


/* Query 1:  */
SELECT Serial_no FROM ROBOT WHERE Serial_no not in (
        SELECT ROBOT.Serial_no from ROBOT, SALE WHERE ROBOT.Serial_no=SALE.Serial_no);

/* Query 2: */
SELECT Sale_Price,
        CASE WHEN Sale_Price <= 10000 THEN 'à accepted-deal price'
        WHEN Sale_Price >= 20000 and Sale_Price <= 25000 THEN 'à average-deal price'
        WHEN sale_Price > 50000 THEN 'à rejected-deal price'
        END AS DealCategory
FROM SALE;





Screesnshots of queries and output:


Related Solutions

Use adventure works 2014 database to solve the following questions in SQL management studio. 1. Create...
Use adventure works 2014 database to solve the following questions in SQL management studio. 1. Create a stored procedure that will receive parameters (all non-nullable fields should be supplied except the primary key which should be auto created still) to add a customer, single email, and single phone. The procedure should run it's code in a transaction and if any part of the add fails then the transaction should rollback. 2. Provide this query from previous assignments written with an...
This is t a relational database please write SQL queries to solve the listed questions. The...
This is t a relational database please write SQL queries to solve the listed questions. The database is a variation of the “Movie Database” . There are several differences in it, so look it over carefully before writing your SQL queries Notes: TheaterNum, MovieNum, and ActorNum are numeric primary key fields in their respective tables. Movie and actor names are not assumed to be unique unless specified otherwise in a question. In the THEATER table, Capacity is the number of...
Use the following information to create SQL commands to retrieve data from Henry Books database :...
Use the following information to create SQL commands to retrieve data from Henry Books database : For each book, list the book code, book title, publisher code, and publisher name. Order the results by publisher name. For each book published by Plume, list the book code, book title, and price. List the book title, book code, and price of each book published by Plume that has a book price of at least $14. List the book code, book title, and...
Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
Use a single SQL statement to create a relational table and to load into the table...
Use a single SQL statement to create a relational table and to load into the table department name, subject code, year of running and session of running that offered by the departments. Note that a running subject offered by a department means a lecturer of the department has been assigned to teach the subject. Next, enforce the appropriate consistency constraints on the new table.    When ready use SELECT statement to list the contents of the relational table created and...
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name...
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name varchar(35) not null, v_contact varchar(15) not null, v_areacode char(3) not null, v_phone char(8) not null, v_state char(2) not null, v_order char(1) not null, primary key (v_code)); create table product (p_code varchar(10) constraint product_p_code_pk primary key, p_descript varchar(35) not null, p_indate datetime not null, p_qoh integer not null, p_min integer not null, p_price numeric (8,2) not null, p_discount numeric (4,2) not null, v_code integer, constraint...
do the following SQL programming tasks: Use the CREATE TABLE statement to build the sample table...
do the following SQL programming tasks: Use the CREATE TABLE statement to build the sample table (MODULE) Use the INSERT INTO statement to populate it - use either the data in the image or your own Write an SQL query to display the whole populated table Write an SQL query to display certain combinations of columns (use your imagination) Write an SQL query to extract certain combinations of columns and rows (imagination again!)
Use the data in the following table for the next seven questions. Note that "%∆" is...
Use the data in the following table for the next seven questions. Note that "%∆" is shorthand for "percentage change." If the answer is a percentage, please just enter the number. Thus, say an answer of yours is 3.5%, then below you would enter "3.5" (without the quotes) in the box below. Be careful not to include the percent symbol. Also, please use just one decimal place. year real GDP (trillions) nominal GDP (trillions) CPI %∆CPI from the previous year...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
Please create the SQL queries using the lryics database under question 4 and use "select *...
Please create the SQL queries using the lryics database under question 4 and use "select * from..." after each query to show the effects of your data manipulation query. Thanks for help 1. The title 'Time Flies' now has a new track, the 11th track 'Spring', which is 150 seconds long and has only a MP3 file. Insert the new track into Tracks table (Don’t hand-code any data for insert that can be looked up from the Titles table). 2....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT