Question

In: Computer Science

All the question should be solved using IF statement Q1) List the Full Name, the city,...

All the question should be solved using IF statement
Q1) List the Full Name, the city, and the state of all members, and order them by their first name in descending order (Z-A) if they are from 'KY' or by their last name in ascending order (A-Z) when they are from 'TN' state.

Q2) List the total number of movies for each genre (FAMILY, ACTION, DRAMA, COMEDY).

- Comment the following two lines if creating database in Mimir or Bluenose
create schema if not exists DVD_vidrental;
use DVD_vidrental;

DROP TABLE IF EXISTS `detailrental`;
DROP TABLE IF EXISTS `rental`;
DROP TABLE IF EXISTS `video`;
DROP TABLE IF EXISTS `movie`;
DROP TABLE IF EXISTS `price`;
DROP TABLE IF EXISTS `membership`;

CREATE TABLE `membership` (
`MEM_NUM` decimal(8,0) NOT NULL,
`MEM_FNAME` varchar(30) NOT NULL,
`MEM_LNAME` varchar(30) NOT NULL,
`MEM_STREET` varchar(120) DEFAULT NULL,
`MEM_CITY` varchar(50) DEFAULT NULL,
`MEM_STATE` char(2) DEFAULT NULL,
`MEM_ZIP` char(5) DEFAULT NULL,
`MEM_BALANCE` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`MEM_NUM`)
);

CREATE TABLE `price` (
`PRICE_CODE` decimal(2,0) NOT NULL,
`PRICE_DESCRIPTION` varchar(20) NOT NULL,
`PRICE_RENTFEE` decimal(5,2) DEFAULT NULL,
`PRICE_DAILYLATEFEE` decimal(5,2) DEFAULT NULL,
PRIMARY KEY (`PRICE_CODE`)
);

CREATE TABLE `movie` (
`MOVIE_NUM` decimal(8,0) NOT NULL,
`MOVIE_TITLE` varchar(75) NOT NULL,
`MOVIE_YEAR` decimal(4,0) DEFAULT NULL,
`MOVIE_COST` decimal(5,2) DEFAULT NULL,
`MOVIE_GENRE` varchar(50) DEFAULT NULL,
`PRICE_CODE` decimal(2,0) DEFAULT NULL,
PRIMARY KEY (`MOVIE_NUM`),
KEY `PRICE_CODE` (`PRICE_CODE`),
CONSTRAINT `movie_ibfk_1` FOREIGN KEY (`PRICE_CODE`) REFERENCES `price` (`PRICE_CODE`)
);

CREATE TABLE `video` (
`VID_NUM` decimal(8,0) NOT NULL,
`VID_INDATE` date DEFAULT NULL,
`MOVIE_NUM` decimal(8,0) DEFAULT NULL,
PRIMARY KEY (`VID_NUM`),
KEY `MOVIE_NUM` (`MOVIE_NUM`),
CONSTRAINT `video_ibfk_1` FOREIGN KEY (`MOVIE_NUM`) REFERENCES `movie` (`MOVIE_NUM`)
);

CREATE TABLE `rental` (
`RENT_NUM` decimal(8,0) NOT NULL,
`RENT_DATE` date DEFAULT NULL,
`MEM_NUM` decimal(8,0) DEFAULT NULL,
PRIMARY KEY (`RENT_NUM`),
KEY `MEM_NUM` (`MEM_NUM`),
CONSTRAINT `rental_ibfk_1` FOREIGN KEY (`MEM_NUM`) REFERENCES `membership` (`MEM_NUM`)
);

CREATE TABLE `detailrental` (
`RENT_NUM` decimal(8,0) NOT NULL,
`VID_NUM` decimal(8,0) NOT NULL,
`DETAIL_FEE` decimal(5,2) DEFAULT NULL,
`DETAIL_DUEDATE` date DEFAULT NULL,
`DETAIL_RETURNDATE` date DEFAULT NULL,
`DETAIL_DAILYLATEFEE` decimal(5,2) DEFAULT NULL,
PRIMARY KEY (`RENT_NUM`,`VID_NUM`),
KEY `VID_NUM` (`VID_NUM`),
CONSTRAINT `detailrental_ibfk_1` FOREIGN KEY (`RENT_NUM`) REFERENCES `rental` (`RENT_NUM`),
CONSTRAINT `detailrental_ibfk_2` FOREIGN KEY (`VID_NUM`) REFERENCES `video` (`VID_NUM`)
);

START TRANSACTION;

INSERT INTO `membership` VALUES (102,'TAMI','DAWSON','2632 TAKLI CIRCLE','NORENE','TN','37136',11.00),
(103,'CURT','KNIGHT','4025 CORNELL COURT','FLATGAP','KY','41219',6.00),
(104,'JAMAL','MELENDEZ','788 EAST 145TH AVENUE','QUEBECK','TN','38579',0.00),
(105,'IVA','MCCLAIN','6045 MUSKET BALL CIRCLE','SUMMIT','KY','42783',15.00),
(106,'MIRANDA','PARKS','4469 MAXWELL PLACE','GERMANTOWN','TN','38183',0.00),
(107,'ROSARIO','ELLIOTT','7578 DANNER AVENUE','COLUMBIA','TN','38402',5.00),
(108,'MATTIE','GUY','4390 EVERGREEN STREET','LILY','KY','40740',0.00),
(109,'CLINT','OCHOA','1711 ELM STREET','GREENEVILLE','TN','37745',10.00),
(110,'LEWIS','ROSALES','4524 SOUTHWIND CIRCLE','COUNCE','TN','38326',0.00),
(111,'STACY','MANN','2789 EAST COOK AVENUE','MURFREESBORO','TN','37132',8.00),
(112,'LUIS','TRUJILLO','7267 MELVIN AVENUE','HEISKELL','TN','37754',3.00),
(113,'MINNIE','GONZALES','6430 VASILI DRIVE','WILLISTON','TN','38076',0.00);

INSERT INTO `price` VALUES (1,'Standard',3.00,1.00),
(2,'New Release',4.50,3.00),(3,'Discount',2.50,1.00),
(4,'Weekly Special',2.00,0.50);
INSERT INTO `movie` VALUES (1234,'The Cesar Family Christmas',2014,39.95,'FAMILY',2),
(1235,'Smokey Mountain Wildlife',2011,59.95,'ACTION',3),(1236,'Richard Goodhope',2015,59.95,'DRAMA',2),
(1237,'Beatnik Fever',2014,29.95,'COMEDY',2),(1238,'Constant Companion',2015,89.95,'DRAMA',NULL),
(1239,'Where Hope Dies',2005,25.49,'DRAMA',3),(1245,'Time to Burn',2015,45.49,'ACTION',3),
(1246,'What He Doesn\'t Know',2013,58.29,'COMEDY',1);
INSERT INTO `video` VALUES (34341,'2014-01-22',1235),(34342,'2014-01-22',1235),
(34366,'2016-03-02',1236),(34367,'2016-03-02',1236),(34368,'2016-03-02',1236),
(34369,'2016-03-02',1236),(44392,'2015-10-21',1237),(44397,'2015-10-21',1237),
(54321,'2015-06-18',1234),(54324,'2015-06-18',1234),(54325,'2015-06-18',1234),
(59237,'2016-02-14',1237),(61353,'2013-01-28',1245),(61354,'2013-01-28',1245),
(61367,'2015-07-30',1246),(61369,'2015-07-30',1246),(61388,'2014-01-25',1239);
INSERT INTO `rental` VALUES (1001,'2016-03-01',103),(1002,'2016-03-01',105),
(1003,'2016-03-02',102),(1004,'2016-03-02',110),(1005,'2016-03-02',111),
(1006,'2016-03-02',107),(1007,'2016-03-02',104),(1008,'2016-03-03',105),(1009,'2016-03-03',111);
INSERT INTO `detailrental` VALUES (1001,34342,2.00,'2016-03-04','2016-03-02',NULL),
(1001,34366,3.50,'2016-03-04','2016-03-02',3.00),(1001,61353,2.00,'2016-03-04','2016-03-03',1.00),
(1002,59237,3.50,'2016-03-04','2016-03-04',3.00),(1003,54325,3.50,'2016-03-04','2016-03-09',3.00),
(1003,61369,2.00,'2016-03-06','2016-03-09',1.00),(1003,61388,0.00,'2016-03-06','2016-03-09',1.00),
(1004,34341,2.00,'2016-03-07','2016-03-07',1.00),(1004,34367,3.50,'2016-03-05','2016-03-07',3.00),
(1004,44392,3.50,'2016-03-05','2016-03-07',3.00),(1005,34342,2.00,'2016-03-07','2016-03-05',1.00),
(1005,44397,3.50,'2016-03-05','2016-03-05',3.00),(1006,34366,3.50,'2016-03-05','2016-03-04',3.00),
(1006,61367,2.00,'2016-03-07',NULL,1.00),(1007,34368,3.50,'2016-03-05',NULL,3.00),
(1008,34369,3.50,'2016-03-05','2016-03-05',3.00),
(1009,54324,3.50,'2016-03-05',NULL,3.00);

COMMIT;

Solutions

Expert Solution

Query 1:

select CONCAT(mem_fname,' ',mem_lname) as FULL_NAME,mem_state,mem_city from membership order by if(mem_state ='KY',mem_fname ,mem_lname) DESC;

OUTPUT

+-----------------+-----------+--------------+
| FULL_NAME       | mem_state | mem_city     |
+-----------------+-----------+--------------+
| LUIS TRUJILLO   | TN        | HEISKELL     |
| LEWIS ROSALES   | TN        | COUNCE       |
| MIRANDA PARKS   | TN        | GERMANTOWN   |
| CLINT OCHOA     | TN        | GREENEVILLE  |
| JAMAL MELENDEZ  | TN        | QUEBECK      |
| MATTIE GUY      | KY        | LILY         |
| STACY MANN      | TN        | MURFREESBORO |
| IVA MCCLAIN     | KY        | SUMMIT       |
| MINNIE GONZALES | TN        | WILLISTON    |
| ROSARIO ELLIOTT | TN        | COLUMBIA     |
| TAMI DAWSON     | TN        | NORENE       |
| CURT KNIGHT     | KY        | FLATGAP      |
+-----------------+-----------+--------------+

Query 2:

Select COUNT(CASE when movie_genre='FAMILY' THEN 1 end) as family,COUNT(CASE when movie_genre='ACTION' THEN 1 end)as action,COUNT(CASE when movie_genre='DRAMA' THEN 1 end) as drama,COUNT(CASE when movie_genre='COMEDY' THEN 1 end) as comedy from movie;

OUTPUT

+--------+--------+-------+--------+
| family | action | drama | comedy |
+--------+--------+-------+--------+
|      1 |      2 |     3 |      2 |
+--------+--------+-------+--------+
1 row in set (0.001 sec)

SCREENSHOT


Related Solutions

I have attached the following script file Q1) List the full name of members, their DETAIL_DAILYLATEFEE...
I have attached the following script file Q1) List the full name of members, their DETAIL_DAILYLATEFEE and the average of DETAIL_DAILYLATEFEE for all members whose DETAIL_DAILYLATEFEE is less than the average of all DETAIL_DAILYLATEFEE. Your query MUST contain a subquery. Your result should be as shown below. Note that each member is only listed once. Required: AVG(DETAIL_DAILYLATEFEE) CONCAT DISTINCT Restricted: GROUP BY Q2) Management is also interested in finding out the age of their movies (i.e. how old the movies...
List customer id, customer full name (Last name, full name, state) for those customers that have...
List customer id, customer full name (Last name, full name, state) for those customers that have ordered more than once. List customers (order id, customer id, and customer last name) that had more than 2 -- products in their order. Order your result based on customer id followed by order id SQL SERVER DATABASE
Evaluate the statement that one city should provide all the electricity for both cities, while the...
Evaluate the statement that one city should provide all the electricity for both cities, while the other provides all the water
SQL statmen: List the first name, the last name, the address, the city, the state, the...
SQL statmen: List the first name, the last name, the address, the city, the state, the branchNo, and the email of agents working in the branch B005 and having email addresses ending with extensions different from .com.
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...
Company: Citigroup Company analysis: 1)Full company name; home office (city, state, country); name of CEO and...
Company: Citigroup Company analysis: 1)Full company name; home office (city, state, country); name of CEO and name of President or indicate if same; stock symbol; stock exchange where stock is traded; closing stock price as of the Friday before the date the project is due. 2)History of the company. Where was the company founded and who was/were the founders? Indicate any major events in the company’s history like mergers or acquisitions? 3)What primary industry does this company compete in and...
Please answer all question using a full paragraph, watch you grammar and syntax. a. What is...
Please answer all question using a full paragraph, watch you grammar and syntax. a. What is trend in investor ratios of Walgreens - use ratios in the answer? (please use at least three sentences. b. What is trend in investors ratios of CVS - use ratios in the answer? (please use at least three sentences) c. Which company has had the better investor ration over the last the years - explain using ratios? ( please use at least three sentences)...
Please answer all question using a full paragraph, watch you grammar and syntax. a. What is...
Please answer all question using a full paragraph, watch you grammar and syntax. a. What is trend in Long Term Debt Paying ability ratios of CVS over the last three years - Explain using ratios and three sentences? b. What is trend in Long Term Debt Paying Ability ratios of Walgreens over the last three years - Explain using rations and three sentences? c. Which company has had better Long Term Debt Paying baility ratios over the last 3 years?...
List department name, employee id, and employee name for all employees in department name order. Repeat...
List department name, employee id, and employee name for all employees in department name order. Repeat for department #10 only. List the course ID, course name, section, instructor name, day, time, and room for all course sections. List the course ID, course name, section, student ID, and student name for CRN 1003. Display the list in ascending order of student last and first names. DROP TABLE registration; DROP TABLE sections; DROP TABLE courses; DROP TABLE students; DROP TABLE instructors; CREATE...
Can all problems in Karp 21 be solved using an Exhaustive search or Brute force? And...
Can all problems in Karp 21 be solved using an Exhaustive search or Brute force? And why
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT