Skip to content

Commit 559099e

Browse files
committed
Updating Documentation
1 parent f5ec341 commit 559099e

2 files changed

Lines changed: 205 additions & 52 deletions

File tree

‎README.md‎

Lines changed: 205 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,277 @@
11
# java-sql
22

33
A student that completes this project shows that they can:
4+
45
* Query data from a single table
56
* Query data from multiple tables
6-
* Create a new datadaase using PostgreSQL
7+
* Create a new database using PostgreSQL
78

8-
# Introduction
9+
## Introduction
910

1011
Working with SQL
1112

12-
# Instructions
13+
## Instructions
1314

1415
ReImport the Northwind database into PostgreSQL using pgAdmin. This is the same data we used during the guided project.
1516

16-
clone https://github.com/pthom/northwind_psql.git
17-
18-
## pgAdmin
17+
* [ ] ***pgAdmin data refresh***
1918

20-
* Right Click Databases
21-
* Create
22-
* type in northwind2
19+
* Select the northwind database created during the guided project.
2320

2421
* Tools -> Query Tool
25-
* Open file northwind.sql (from cloned repo)
22+
* Open file northwind.sql (you used this script during the guided project)
2623
* Execute
2724

2825
* Look under
29-
* northwind2 -> Schemas -> public -> tables
26+
* northwind -> Schemas -> public -> tables
3027

3128
* Clear query windows
3229

33-
Answer the following data queries. Keep track of the SQL you write by pasting it into this document under its appropriate header below. You will be submitting that through the regular fork, change, pull process.
30+
### Answer the following data queries. Keep track of the SQL you write by pasting it into this document under its appropriate header below in the provided SLQ code block. You will be submitting that through the regular fork, change, pull process.
31+
32+
* [ ] ***find all customers that live in London. Returns 6 records***
33+
34+
<details><summary>hint</summary>
35+
<p>
36+
* This can be done with SELECT and WHERE clauses
37+
</p>
38+
</details>
39+
40+
```SQL
41+
42+
```
43+
44+
* [ ] ***find all customers with postal code 1010. Returns 3 customers***
3445

46+
<details><summary>hint</summary>
47+
<p>
48+
* This can be done with SELECT and WHERE clauses
49+
</p>
50+
</details>
3551

36-
### find all customers that live in London. Returns 6 records.
37-
> This can be done with SELECT and WHERE clauses
52+
```SQL
3853

54+
```
3955

40-
### find all customers with postal code 1010. Returns 3 customers.
41-
> This can be done with SELECT and WHERE clauses
56+
* [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510***
4257

58+
<details><summary>hint</summary>
59+
<p>
60+
* This can be done with SELECT and WHERE clauses
61+
</p>
62+
</details>
4363

44-
### find the phone number for the supplier with the id 11. Should be (010) 9984510.
45-
> This can be done with SELECT and WHERE clauses
64+
```SQL
4665

66+
```
4767

48-
### list orders descending by the order date. The order with date 1998-05-06 should be at the top.
49-
> This can be done with SELECT, WHERE, and ORDER BY clauses
68+
* [ ] ***list orders descending by the order date. The order with date 1998-05-06 should be at the top***
5069

70+
<details><summary>hint</summary>
71+
<p>
72+
* This can be done with SELECT, WHERE, and ORDER BY clauses
73+
</p>
74+
</details>
5175

52-
### find all suppliers who have names longer than 20 characters. You can use `length(company_name)` to get the length of the name. Returns 11 records.
53-
> This can be done with SELECT and WHERE clauses
76+
```SQL
5477

78+
```
5579

56-
### find all customers that include the word 'MARKET' in the contact title. Should return 19 records.
57-
> This can be done with SELECT and a WHERE clause using the LIKE keyword
80+
* [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records***
5881

59-
> Don't forget the wildcard '%' symbols at the beginning and end of your substring to denote it can appear anywhere in the string in question
82+
<details><summary>hint</summary>
83+
<p>
84+
* This can be done with SELECT and WHERE clauses
85+
* You can use `length(company_name)` to get the length of the name
86+
</p>
87+
</details>
6088

61-
> Remember to convert your contact title to all upper case for case insenstive comparing so upper(contact_title)
89+
```SQL
6290

91+
```
6392

64-
### add a customer record for
93+
* [ ] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records***
94+
95+
<details><summary>hint</summary>
96+
<p>
97+
* This can be done with SELECT and a WHERE clause using the LIKE keyword
98+
* Don't forget the wildcard '%' symbols at the beginning and end of your substring to denote it can appear anywhere in the string in question
99+
* Remember to convert your contact title to all upper case for case insensitive comparing so upper(contact_title)
100+
</p>
101+
</details>
102+
103+
```SQL
104+
105+
```
106+
107+
* [ ] ***add a customer record for***
65108
* customer id is 'SHIRE'
66109
* company name is 'The Shire'
67110
* contact name is 'Bilbo Baggins'
68111
* the address is '1 Hobbit-Hole'
69-
* ths city is 'Bag End'
112+
* the city is 'Bag End'
70113
* the postal code is '111'
71114
* the country is 'Middle Earth'
72-
> This can be done with the INSERT INTO clause
115+
<details><summary>hint</summary>
116+
<p>
117+
* This can be done with the INSERT INTO clause
118+
</p>
119+
</details>
120+
121+
```SQL
122+
123+
```
124+
125+
* [ ] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_***
73126

127+
<details><summary>hint</summary>
128+
<p>
129+
* This can be done with UPDATE and WHERE clauses
130+
</p>
131+
</details>
74132

75-
### update _Bilbo Baggins_ record so that the postal code changes to _"11122"_.
76-
> This can be done with UPDATE and WHERE clauses
133+
```SQL
77134

135+
```
78136

79-
### list orders grouped by customer showing the number of orders per customer. _Rattlesnake Canyon Grocery_ should have 18 orders.
80-
> This can be done with SELECT, COUNT, JOIN and GROUP BY clauses. Your count should focus on a field in the Orders table, not the Customer table
137+
* [ ] ***list orders grouped and ordered by customer company name showing the number of orders per customer company name. _Rattlesnake Canyon Grocery_ should have 18 orders***
81138

82-
> There is more information about the COUNT clause on [W3 Schools](https://www.w3schools.com/sql/sql_count_avg_sum.asp)
139+
<details><summary>hint</summary>
140+
<p>
141+
* This can be done with SELECT, COUNT, JOIN and GROUP BY clauses. Your count should focus on a field in the Orders table, not the Customer table
142+
* There is more information about the COUNT clause on [W3 Schools](https://www.w3schools.com/sql/sql_count_avg_sum.asp)
143+
</p>
144+
</details>
83145

146+
```SQL
84147

85-
### list customers names and the number of orders per customer. Sort the list by number of orders in descending order. _Save-a-lot Markets should be at the top with 31 orders followed by _Ernst Handle_ with 30 orders. Last should be _Centro comercial Moctezuma_ with 1 order.
86-
> This can be done by adding an ORDER BY clause to the previous answer
148+
```
87149

150+
* [ ] ***list customers by contact name and the number of orders per contact name. Sort the list by number of orders in descending order. _Jose Pavarotti_ should be at the top with 31 orders followed by _Roland Mendal_ with 30 orders. Last should be _Francisco Chang_ with 1 order***
88151

89-
### list orders grouped by customer's city showing number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders.
90-
> This is very similar to the previous two queries, however, it focuses on the City rather than the CustomerName
152+
<details><summary>hint</summary>
153+
<p>
154+
* This can be done by adding an ORDER BY clause to the previous answer and changing the group by field
155+
</p>
156+
</details>
91157

158+
```SQL
159+
160+
```
161+
162+
* [ ] ***list orders grouped by customer's city showing number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders***
163+
164+
<details><summary>hint</summary>
165+
<p>
166+
* This is very similar to the previous two queries, however, it focuses on the City rather than the Customer Names
167+
</p>
168+
</details>
169+
170+
```SQL
171+
172+
```
92173

93174
## Data Normalization
94175

95176
Note: This step does not use PostgreSQL!
96177

97-
Take the following data and normalize it into a 3NF database. You can use the website https://www.tablesgenerator.com/markdown_tables# to help generate Markdown Tables.
178+
* [ ] ***Take the following data and normalize it into a 3NF database***
98179

99180
| Person Name | Pet Name | Pet Type | Pet Name 2 | Pet Type 2 | Pet Name 3 | Pet Type 3 | Fenced Yard | City Dweller |
100181
|-------------|----------|----------|------------|------------|------------|------------|-------------|--------------|
101182
| Jane | Ellie | Dog | Tiger | Cat | Toby | Turtle | No | Yes |
102183
| Bob | Joe | Horse | | | | | No | No |
103184
| Sam | Ginger | Dog | Miss Kitty | Cat | Bubble | Fish | Yes | No |
104185

186+
Below are some empty tables to be used to normalize the database
187+
188+
* Not all of the cells will contain data in the final solution
189+
* Feel free to edit these tables as necessary
190+
191+
Table Name:
192+
193+
| | | | | | | | | |
194+
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
195+
| | | | | | | | | |
196+
| | | | | | | | | |
197+
| | | | | | | | | |
198+
| | | | | | | | | |
199+
| | | | | | | | | |
200+
| | | | | | | | | |
201+
| | | | | | | | | |
202+
203+
Table Name:
204+
205+
| | | | | | | | | |
206+
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
207+
| | | | | | | | | |
208+
| | | | | | | | | |
209+
| | | | | | | | | |
210+
| | | | | | | | | |
211+
| | | | | | | | | |
212+
| | | | | | | | | |
213+
| | | | | | | | | |
214+
215+
Table Name:
216+
217+
| | | | | | | | | |
218+
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
219+
| | | | | | | | | |
220+
| | | | | | | | | |
221+
| | | | | | | | | |
222+
| | | | | | | | | |
223+
| | | | | | | | | |
224+
| | | | | | | | | |
225+
| | | | | | | | | |
226+
227+
Table Name:
228+
229+
| | | | | | | | | |
230+
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
231+
| | | | | | | | | |
232+
| | | | | | | | | |
233+
| | | | | | | | | |
234+
| | | | | | | | | |
235+
| | | | | | | | | |
236+
| | | | | | | | | |
237+
| | | | | | | | | |
238+
105239
---
106-
## Stretch Goals
107240

108-
### delete all customers that have no orders. Should delete 2 (or 3 if you haven't deleted the record added) records.
241+
### Stretch Goals
242+
243+
* [ ] ***delete all customers that have no orders. Should delete 2 (or 3 if you haven't deleted the record added) records***
244+
245+
```SQL
246+
247+
```
248+
249+
* [ ] ***Create Database and Table: After creating the database, tables, columns, and constraint, generate the script necessary to recreate the database. This script is what you will submit for review***
250+
251+
* use pgAdmin to create a database, naming it `budget`.
252+
* add an `accounts` table with the following _schema_:
253+
254+
* `id`, numeric value with no decimal places that should autoincrement.
255+
* `name`, string, add whatever is necessary to make searching by name faster.
256+
* `budget` numeric value.
257+
258+
* constraints
259+
* the `id` should be the primary key for the table.
260+
* account `name` should be unique.
261+
* account `budget` is required.
109262

110-
## Create Database and Table
263+
```SQL
111264

112-
### After creating the database, tables, columns, and constraint, generate the script necessary to recreate the database. This script is what you will submit for review.
265+
```
113266

114-
- use pgAdmin to create a database, naming it `budget`.
115-
- add an `accounts` table with the following _schema_:
267+
To see the script
116268

117-
- `id`, numeric value with no decimal places that should autoincrement.
118-
- `name`, string, add whatever is necessary to make searching by name faster.
119-
- `budget` numeric value.
269+
* Right Click on the database name
270+
* Select Backup...
271+
* Set a filename
272+
* To put the file backup.sql in your home directory, you could use `backup.sql`
273+
* Set format to `Plain`
274+
* The script you want is now in the text file named above.
275+
* Copy the script from the text file into the SQL code block above!
120276

121-
- constraints
122-
- the `id` should be the primary key for the table.
123-
- account `name` should be unique.
124-
- account `budget` is required.
277+
![Database Script](assets/jx-12-m3-script.gif)

‎assets/jx-12-m3-script.gif‎

12 MB
Loading

0 commit comments

Comments
 (0)