Uploaded by Nata Khabirova

CIS336Lab4 StudentAnswerSheet

advertisement
CIS336: Lab 4 Answer Sheet
Your name: Natalia Khabirova
Solution 1:
~Paste your solution query here~
SELECT customer_first_name, customer_last_name, customer_phone FROM
customers ORDER BY customer_last_name, customer_first_name;
~Paste your solution query results text here~
customer_first_name customer_last_name customer_phone
Trisha
Anum
3105552732
Dakota
Baylee
2135554322
Korah
Blanca
6145554435
Julian
Carson
6175550700
Derek
Chaddick
5155556130
Deborah
Davis
5595558060
Mikayla
Davis
2025555561
Kelsey
Eulalia
2095557500
Rashad
Holbrooke
5595558625
Kaitlin
Hostlery
8005551957
Ania
Irvin
7145559000
Samuel
Jacobsen
4155553434
Justin
Javen
8005550037
Erick
Kaleigh
7045553500
Gonzalo
Keeton
2015559742
Karina
Lacy
8005557000
Kyle
Marissa
9475553900
Kendall
Mayte
5135553043
Johnathon
Millerton
2125554800
Thalia
Neftaly
5595556245
Kurt
Nickalus
8055550584
Marvin
Quintin
6145558600
Yash
Randall
2095551205
Anders
Rohansen
3385556772
Kirsten
Story
2065559115
Page 1
Solution 2:
~Paste your solution query here~
SELECT CONCAT_WS(' ', customer_first_name, customer_last_name) AS
"firstname_lastname" , customer_phone AS "Phone" FROM customers WHERE
customer_state IN ( 'NY', 'NJ', 'DC' ) ORDER BY customer_phone;
~Paste your solution query results text here~
firstname_lastname Phone
Gonzalo Keeton
2015559742
Mikayla Davis
2025555561
Kirsten Story
2065559115
Johnathon Millerton 2125554800
Justin Javen
8005550037
Solution 3:
~Paste your solution query here~
SELECT DISTINCT customer_city AS "City" FROM customers ORDER BY customer_city
DESC;
~Paste your solution query results text here~
City
Washington
Valencia
Tarrytown
Takoma Park
San Francisco
Sacramento
Phoenix
Palo Alto
Orange
New York
Manhatttan Beach
Madison
Los Angeles
Page 2
Fresno
Fairfield
Columbus
Cleves
Cincinnati
Charlotte
Solution 4:
~Paste your solution query here~
select title, unit_price as Original, ROUND(unit_price *0.25, 2) as Sale from
items order by unit_price;
~Paste your solution query results text here~
title
Original Sale
Race Car Sounds
13.00
3.25
Rude Noises
13.00
3.25
No Fixed Address
16.95
4.24
No Rest For The Weary
16.95
4.24
Zone Out With Umami
16.95
4.24
Etcetera
17.00
4.25
On The Road With Burt Ruggles
17.50
4.38
Burt Ruggles: An Intimate Portrait
17.95
4.49
More Songs About Structures and Comestibles 17.95
4.49
Umami In Concert
17.95
4.49
Solution 5:
~Paste your solution query here~
SELECT customer_first_name, customer_last_name, customer_city FROM customers
WHERE customer_zip LIKE '4%'
~Paste your solution query results text here~
customer_first_name customer_last_name customer_city
Korah
Blanca
Columbus
Kendall
Mayte
Cleves
Kaitlin
Hostlery
Cincinnati
Page 3
Marvin
Quintin
Columbus
Solution 6:
~Paste your solution query here~
SELECT order_id, order_date, DATE_FORMAT( order_date, '%M %e, %Y') AS
"Ordered" FROM orders WHERE order_date >= '2014/03/01' AND order_date <=
'2014/04/30' ;
~Paste your solution query results text here~
order_id order_date Ordered
523
2014-03-07 March 7, 2014
548
2014-03-22 March 22, 2014
550
2014-03-23 March 23, 2014
601
2014-04-21 April 21, 2014
607
2014-04-25 April 25, 2014
Solution 7:
~Paste your solution query here~
SELECT order_id, order_date, DATE_FORMAT(order_date, '%m/%d/%y') AS "Ordered"
FROM orders WHERE order_date BETWEEN '2014/05/1' AND '2014/05/31';
~Paste your solution query results text here~
order_id
624
627
630
651
658
order_date
2014-05-04
2014-05-05
2014-05-08
2014-05-19
2014-05-23
Ordered
05/04/14
05/05/14
05/08/14
05/19/14
05/23/14
Solution 8:
~Paste your solution query here~
SELECT order_id, order_date, DATEDIFF( shipped_date, order_date) AS Days FROM
orders WHERE DATEDIFF( shipped_date, order_date) >= 15 ORDER BY Days DESC;
~Paste your solution query results text here~
order_id order_date Days
Page 4
413
180
298
479
548
321
158
2013-12-05
2013-04-25
2013-08-18
2014-01-30
2014-03-22
2013-09-09
2013-04-04
37
35
35
32
27
26
16
Solution 9:
~Paste your solution query here~
SELECT order_id, customer_id, order_date FROM orders WHERE shipped_date IS
NULL ORDER BY order_date ASC;
~Paste your solution query results text here~
order_id customer_id order_date
824
1
2014-08-01
827
18
2014-08-02
829
9
2014-08-02
Solution 10:
~Paste your solution query here~
SELECT order_id, order_date, shipped_date, DAYNAME( shipped_date) AS
"Order_Day" FROM orders WHERE shipped_date IS NOT NULL AND DAYNAME(
shipped_date) = 'Saturday' OR DAYNAME( shipped_date) = 'Sunday' ORDER BY
order_date DESC;
~Paste your solution query results text here~
order_id order_date
796
2014-07-19
687
2014-06-05
630
2014-05-08
627
2014-05-05
607
2014-04-25
601
2014-04-21
523
2014-03-07
shipped_date Order_Day
2014-07-26 Saturday
2014-06-08 Sunday
2014-05-18 Sunday
2014-05-10 Saturday
2014-05-04 Sunday
2014-04-27 Sunday
2014-03-15 Saturday
Page 5
413
381
321
298
242
231
165
158
97
29
19
2013-12-05
2013-11-08
2013-09-09
2013-08-18
2013-06-24
2013-06-14
2013-04-11
2013-04-04
2013-01-29
2012-11-05
2012-10-23
2014-01-11
2013-11-16
2013-10-05
2013-09-22
2013-07-06
2013-06-22
2013-04-13
2013-04-20
2013-02-02
2012-11-11
2012-10-28
Saturday
Saturday
Saturday
Sunday
Saturday
Saturday
Saturday
Saturday
Saturday
Sunday
Sunday
Solution 11:
~Paste your solution query here~
SELECT customer_last_name, customer_phone, customer_fax FROM customers WHERE
customer_fax IS NOT NULL
~Paste your solution query results text here~
customer_last_name customer_phone customer_fax
Blanca
6145554435
6145553928
Randall
2095551205
2095552262
Hostlery
8005551957
8005552826
Nickalus
8055550584
055556689
Eulalia
2095557500
2095551302
Quintin
6145558600
6145557580
Holbrooke
5595558625
5595558495
Solution 12:
~Paste your solution query here~
INSERT INTO items (item_id, title, artist_id, unit_price) VALUES (11, 'Ode To
My ERD', 15, 12.95); SELECT * FROM items WHERE item_id > 10;
~Paste your solution query results text here~
item_id title
artist_id unit_price
11
Ode To My ERD 15
12.95
Page 6
Solution 13:
~Paste your solution query here~
UPDATE items SET unit_price = 7.95 WHERE item_id = 11; SELECT * FROM items
WHERE item_id > 10
~Paste your solution query results text here~
item_id title
artist_id unit_price
11
Ode To My ERD 15
7.95
Solution 14:
~Paste your solution query here~
DELETE FROM items WHERE item_id =11 AND title = 'Ode To My ERD' AND artist_id
= 15 AND unit_price = 12.95; SELECT * FROM items WHERE item_id > 10;
~Paste your solution query results text here~
Solution 15:
~Paste your solution query here~
SELECT CONCAT( customer_first_name, ',', customer_last_name) AS
"Customer", CONCAT ('(', SUBSTRING(customer_phone, 1,3), ')',
SUBSTRING(customer_phone, 4,3), '-', SUBSTRING(customer_phone, 7,4)) AS
"Phone" FROM customers ORDER BY customer_last_name;
~Paste your solution query results text here~
Customer
Trisha,Anum
Dakota,Baylee
Korah,Blanca
Julian,Carson
Derek,Chaddick
Phone
(310)555-2732
(213)555-4322
(614)555-4435
(617)555-0700
(515)555-6130
Page 7
Mikayla,Davis
Deborah,Davis
Kelsey,Eulalia
Rashad,Holbrooke
Kaitlin,Hostlery
Ania,Irvin
Samuel,Jacobsen
Justin,Javen
Erick,Kaleigh
Gonzalo,Keeton
Karina,Lacy
Kyle,Marissa
Kendall,Mayte
Johnathon,Millerton
Thalia,Neftaly
Kurt,Nickalus
Marvin,Quintin
Yash,Randall
Anders,Rohansen
Kirsten,Story
(202)555-5561
(559)555-8060
(209)555-7500
(559)555-8625
(800)555-1957
(714)555-9000
(415)555-3434
(800)555-0037
(704)555-3500
(201)555-9742
(800)555-7000
(947)555-3900
(513)555-3043
(212)555-4800
(559)555-6245
(805)555-0584
(614)555-8600
(209)555-1205
(338)555-6772
(206)555-9115
Page 8
Download