-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChapter_05.sql
148 lines (147 loc) · 4.94 KB
/
Chapter_05.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* @Author: ADITYA KUMAR SINGH <the__martian>
* @Email: [email protected]
* @Filename: Chapter_05.sql
* @Last modified by: the__martian
*/
--------------------------------------------------------------
-- Example
--------------------------------------------------------------
use SalesOrdersExample;
--------------------------------------------------------------
select ProductName as Product, RetailPrice * QuantityOnHand
as 'Inventory Price'
from
Products;
--------------------------------------------------------------
select OrderNumber, OrderDate, ShipDate, cast(ShipDate -
OrderDate as Integer ) DaysElapsed
from
Orders;
--------------------------------------------------------------
use EntertainmentAgencyExample;
--------------------------------------------------------------
select EngagementNumber, concat(cast(cast(EndDate - StartDate
as Integer) + 1 as character), ' day(s)') as DueToRun
from
Engagements;
--------------------------------------------------------------
select EngagementNumber, concat( '$', cast(ContractPrice as
character)) as ContractPrice, concat('$', cast(ContractPrice
* 0.12 as character)) as OurFee, concat('$',
cast(ContractPrice * 0.88 as character))as 'Net Amount'
from
Engagements;
--------------------------------------------------------------
use SchoolSchedulingExample;
--------------------------------------------------------------
select concat(StfLastname, ', ', StfFirstName) as Name,
DateHired, cast(cast(cast('2017-10-01' as date) - DateHired
as Integer)/365 as Integer) as YearsWithSchool
from
Staff
order by
StfLastname, StfFirstName;
--------------------------------------------------------------
select concat(StfLastname, ', ', StfFirstName) as Name,
concat('$', Salary) as Salary, concat('$', 0.07*Salary) as
Bonus
from
Staff;
--------------------------------------------------------------
use BowlingLeagueExample;
--------------------------------------------------------------
select concat( BowlerFirstName, ' ', BowlerLastName) as 'Full
Name', BowlerAddress as Address, concat(BowlerCity, ', ',
BowlerState, ' ', BowlerZip) as CityStateZip, BowlerZip as Zip
from
Bowlers
order by
BowlerZip;
--------------------------------------------------------------
select BowlerID, MatchID, GameNumber, RawScore,
HandiCapScore, HandiCapScore - RawScore as PointDifference
from
Bowler_Scores;
--------------------------------------------------------------
-- Problems
--------------------------------------------------------------
use SalesOrdersExample;
--------------------------------------------------------------
select ProductNumber, WholesalePrice, 0.95 * WholesalePrice
as NewPrice
from
Product_Vendors;
--------------------------------------------------------------
select CustomerID, OrderDate, OrderNumber
from
Orders
order by
CustomerID, OrderDate desc;
--------------------------------------------------------------
select VendName, concat(VendStreetAddress, ' ', VendCity, '
', VendState, ' ', VendZipCode) as Address, VendPhoneNumber
from
Vendors
order by
VendName;
--------------------------------------------------------------
use EntertainmentAgencyExample;
--------------------------------------------------------------
select CustCity, concat(CustLastName, ', ', CustFirstName) as
Customer
from
Customers
order by
CustCity, CustLastName, CustFirstName;
--------------------------------------------------------------
select EntStageName as Name, EntWebPage as 'Website'
from
Entertainers;
--------------------------------------------------------------
---select
--?????????????
--------------------------------------------------------------
use SchoolSchedulingExample;
--------------------------------------------------------------
select concat(StfLastname, ', ', StfFirstName) as Name, Salary
from
Staff
order by
Salary desc;
--------------------------------------------------------------
select concat(StfLastname, ', ', StfFirstName) as Name,
concat('(', StfAreaCode,') ', StfPhoneNumber) as 'Phone
Number'
from
Staff;
--------------------------------------------------------------
select StudCity as City, concat(StudLastName, ', ',
StudFirstName) as Name
from
Students
order by
StudCity;
--------------------------------------------------------------
use BowlingLeagueExample;
--------------------------------------------------------------
--select TourneyLocation as Location, TourneyDate + 364 as
--'Tournament date'
--from Tournaments
--order by TourneyLocation;
--**** Look for how to add days to date in Mysql****--
--------------------------------------------------------------
select concat(BowlerLastName, ', ', BowlerFirstName) as
Name,BowlerPhoneNumber as 'Phone Number'
from
Bowlers
order by
BowlerLastName, BowlerFirstName;
--------------------------------------------------------------
select TeamID, concat(BowlerLastName, ', ', BowlerFirstName)
as Name
from
Bowlers
order by
TeamID;
--------------------------------------------------------------