|
1 | | -# java-sql |
| 1 | +# Introduction |
| 2 | + |
| 3 | +Working with SQL |
| 4 | + |
| 5 | +# Instructions |
| 6 | + |
| 7 | +Surf to [SQL Try Editor at W3Schools.com](https://www.w3schools.com/Sql/tryit.asp?filename=trysql_select_top) |
| 8 | +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. |
| 9 | + |
| 10 | +### **Clicking the `Restore Database` button in the page will repopulate the database with the original data and discard all changes you have made**. |
| 11 | + |
| 12 | +### find all customers that live in London. Returns 6 records. |
| 13 | + |
| 14 | +### find all customers with postal code 1010. Returns 3 customers. |
| 15 | + |
| 16 | +### find the phone number for the supplier with the id 11. Should be (010) 9984510. |
| 17 | + |
| 18 | +### list orders descending by the order date. The order with date 1997-02-12 should be at the top. |
| 19 | + |
| 20 | +### find all suppliers who have names longer than 20 characters. You can use `length(SupplierName)` to get the length of the name. Returns 11 records. |
| 21 | + |
| 22 | +### find all customers that include the word "market" in the name. Should return 4 records. |
| 23 | + |
| 24 | +### add a customer record for _"The Shire"_, the contact name is _"Bilbo Baggins"_ the address is _"1 Hobbit-Hole"_ in _"Bag End"_, postal code _"111"_ and the country is _"Middle Earth"_. |
| 25 | + |
| 26 | +### update _Bilbo Baggins_ record so that the postal code changes to _"11122"_. |
| 27 | + |
| 28 | +### list orders grouped by customer showing the number of orders per customer. _Rattlesnake Canyon Grocery_ should have 7 orders. |
| 29 | + |
| 30 | +### list customers names and the number of orders per customer. Sort the list by number of orders in descending order. _Ernst Handel_ should be at the top with 10 orders followed by _QUICK-Stop_, _Rattlesnake Canyon Grocery_ and _Wartian Herkku_ with 7 orders each. |
| 31 | + |
| 32 | +### list orders grouped by customer's city showing number of orders per city. Returns 58 Records with _Aachen_ showing 2 orders and _Albuquerque_ showing 7 orders. |
| 33 | + |
| 34 | +### delete all customers that have no orders. Should delete 17 (or 18 if you haven't deleted the record added) records. |
| 35 | + |
| 36 | +## Create Database and Table |
| 37 | + |
| 38 | +### Keep track of the code you write and paste at the end of this document |
| 39 | + |
| 40 | +- use [`SQLite Studio`](https://sqlitestudio.pl/index.rvt) to create a database, name it `budget.sqlite3`. |
| 41 | +- add an `accounts` table with the following _schema_: |
| 42 | + |
| 43 | + - `id`, numeric value with no decimal places that should autoincrement. |
| 44 | + - `name`, string, add whatever is necessary to make searching by name faster. |
| 45 | + - `budget` numeric value. |
| 46 | + |
| 47 | +- constraints |
| 48 | + - the `id` should be the primary key for the table. |
| 49 | + - account `name` should be unique. |
| 50 | + - account `budget` is required. |
| 51 | + |
0 commit comments