├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── 02_01 ├── sample_web_analytics.sql └── total_revenue_by_region.sql ├── 03_02 └── descriptive_summary.sql ├── 03_03 └── predictive_model.sql ├── 04_02 ├── README.md ├── create-tables.sql ├── db.py ├── index.html └── main.py ├── 04_03 ├── AppDelegate.swift ├── Customer.swift ├── DBHelper.swift ├── LaunchScreen.storyboard ├── Main.storyboard ├── README.md ├── SceneDelegate.swift └── ViewController.swift ├── 04_04 ├── README.md ├── create-tables.sql ├── db.py ├── index.html ├── main.py └── states.html ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── SQL Careers Assessment.pdf └── Skills Inventory Worksheet.pdf /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) deotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .tmp 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /02_01/sample_web_analytics.sql: -------------------------------------------------------------------------------- 1 | #standardSQL 2 | SELECT 3 | date, 4 | COUNT (DISTINCT visitId) as num_records, 5 | SUM(totals.visits) as num_visits, 6 | SUM(totals.hits) num_hits, 7 | AVG(totals.pageviews) average_page_views, 8 | AVG(totals.transactions) average_transactions, 9 | SUM(totals.totalTransactionRevenue) total_revenue 10 | FROM `bigquery-public-data.google_analytics_sample.ga_sessions*` 11 | GROUP BY date 12 | ORDER BY date 13 | -------------------------------------------------------------------------------- /02_01/total_revenue_by_region.sql: -------------------------------------------------------------------------------- 1 | SELECT geoNetwork.region, 2 | SUM(totals.totalTransactionRevenue) as Total_Revenue 3 | FROM 4 | `bigquery-public-data.google_analytics_sample.ga_sessions_20170801` 5 | WHERE geoNetwork.region IS NOT NULL 6 | GROUP BY geoNetwork.region 7 | ORDER BY Total_Revenue DESC 8 | -------------------------------------------------------------------------------- /03_02/descriptive_summary.sql: -------------------------------------------------------------------------------- 1 | 2 | SELECT 3 | SUMMARY_1.MEASURE as MEASURE, 4 | ST_DEV, 5 | AVERAGE_TOTAL_ORDER, 6 | MIN_TOTAL_DUE, 7 | PERCENTILE_25, 8 | MEDIAN, 9 | PERCENTILE_75, 10 | MAX_TOTAL_DUE 11 | 12 | FROM 13 | (SELECT 'TotalDue' as MEASURE, stddev(TotalDue) as ST_DEV, 14 | avg(TotalDue) as AVERAGE_TOTAL_ORDER, 15 | max(TotalDue) as MAX_TOTAL_DUE, 16 | min(TotalDue) as MIN_TOTAL_DUE 17 | from `sql-careers.HPlusSports.orders`) as SUMMARY_1, 18 | 19 | (SELECT 'TotalDue' as MEASURE, 20 | PERCENTILE_CONT(TotalDue, 0.25) OVER () AS PERCENTILE_25, 21 | PERCENTILE_CONT(TotalDue, 0.5) OVER () AS MEDIAN, 22 | PERCENTILE_CONT(TotalDue, 0.75) OVER () AS PERCENTILE_75 23 | FROM 24 | (SELECT TotalDue FROM `sql-careers.HPlusSports.orders`) as Total 25 | LIMIT 26 | 1) AS SUMMARY_2 27 | WHERE SUMMARY_1.MEASURE = SUMMARY_2.MEASURE 28 | -------------------------------------------------------------------------------- /03_03/predictive_model.sql: -------------------------------------------------------------------------------- 1 | -- Build a Forecasting Model based on Historical Product Sales data 2 | 3 | CREATE OR REPLACE VIEW HPlusSports.forecast_training_data AS 4 | (SELECT orders.OrderDate, 5 | ProductCode, 6 | total_products_sold 7 | FROM `sql-careers.HPlusSports.orders` as orders, 8 | (SELECT OrderID, 9 | p.ProductCode, 10 | SUM(Quantity) as total_products_sold 11 | FROM `sql-careers.HPlusSports.order_item` i ,`sql-careers.HPlusSports.products` p 12 | where i.ProductID = p.ProductID 13 | group by ORDERID, ProductCode) as products_sold 14 | WHERE orders.OrderID = products_sold.OrderID); 15 | 16 | 17 | -- Create A Time Series Based Model 18 | CREATE OR REPLACE MODEL HPlusSports.forecast_model 19 | OPTIONS( 20 | MODEL_TYPE='ARIMA', 21 | TIME_SERIES_TIMESTAMP_COL='OrderDate', 22 | TIME_SERIES_DATA_COL='total_products_sold', 23 | TIME_SERIES_ID_COL='ProductCode', 24 | HOLIDAY_REGION='US' 25 | ) AS 26 | SELECT OrderDate, ProductCode,total_products_sold 27 | FROM `sql-careers.HPlusSports.forecast_training_data` 28 | 29 | -- Evaluate the Model 30 | SELECT * FROM 31 | ML.EVALUATE(MODEL `sql-careers.HPlusSports.forecast_model`); 32 | 33 | 34 | -- Make Predictions for the next 30 days at a confidence interval of 90% 35 | SELECT * 36 | FROM 37 | ML.FORECAST(MODEL HPlusSports.forecast_model, 38 | STRUCT(30 AS horizon, 0.9 AS confidence_level)); 39 | 40 | -- Create a view to build visualization 41 | CREATE OR REPLACE VIEW HPlusSports.forecast_datastudio AS ( 42 | SELECT 43 | OrderDate AS timestamp, 44 | ProductCode, 45 | total_products_sold as history_value, 46 | NULL AS forecast_value, 47 | NULL AS prediction_interval_lower_bound, 48 | NULL AS prediction_interval_upper_bound 49 | FROM 50 | HPlusSports.forecast_training_data 51 | UNION ALL 52 | SELECT 53 | EXTRACT(DATE 54 | FROM 55 | forecast_timestamp) AS timestamp, 56 | ProductCode, 57 | NULL AS history_value, 58 | forecast_value, 59 | prediction_interval_lower_bound, 60 | prediction_interval_upper_bound 61 | FROM 62 | ML.FORECAST(MODEL `sql-careers.HPlusSports.forecast_model`, 63 | STRUCT(30 AS horizon, 0.9 AS confidence_level)) 64 | ORDER BY timestamp 65 | ); 66 | 67 | SELECT * FROM `sql-careers.HPlusSports.forecast_datastudio`; 68 | -------------------------------------------------------------------------------- /04_02/README.md: -------------------------------------------------------------------------------- 1 | For more information on setting up the Google Cloud SDK and AppEngine, visit: https://cloud.google.com/appengine/docs/standard/python3/quickstart 2 | 3 | Quickstart for Cloud SQL for MySQL: https://cloud.google.com/sql/docs/mysql/quickstart 4 | 5 | -------------------------------------------------------------------------------- /04_02/create-tables.sql: -------------------------------------------------------------------------------- 1 | create table customers ( 2 | CustomerID INT NOT NULL, 3 | FirstName VARCHAR(255), 4 | LastName VARCHAR(255), 5 | Email VARCHAR(255), 6 | Phone VARCHAR(255), 7 | Address VARCHAR(255), 8 | City VARCHAR(255), 9 | State VARCHAR(255), 10 | Zipcode VARCHAR(255), 11 | PRIMARY KEY(CustomerID) 12 | ); 13 | 14 | create table census_state_pop ( 15 | statename VARCHAR(255), 16 | pop VARCHAR(255), 17 | code VARCHAR(255) 18 | ); -------------------------------------------------------------------------------- /04_02/db.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pymysql 3 | from flask import jsonify, request 4 | import json 5 | from urllib.request import urlopen 6 | import urllib.error 7 | 8 | db_user = os.environ.get('CLOUD_SQL_USERNAME') 9 | db_password = os.environ.get('CLOUD_SQL_PASSWORD') 10 | db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME') 11 | db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME') 12 | acs_api_key = os.environ.get('ACS_KEY') 13 | 14 | def open_connection(): 15 | unix_socket = '/cloudsql/{}'.format(db_connection_name) 16 | try: 17 | if os.environ.get('GAE_ENV') == 'standard': 18 | conn = pymysql.connect(user=db_user, password=db_password, 19 | unix_socket=unix_socket, db=db_name, 20 | cursorclass=pymysql.cursors.DictCursor 21 | ) 22 | except pymysql.MySQLError as e: 23 | print(e) 24 | 25 | return conn 26 | 27 | 28 | def get_customers(): 29 | conn = open_connection() 30 | with conn.cursor() as cursor: 31 | sql = 'SELECT * FROM customers LIMIT 50;' 32 | result = cursor.execute(sql) 33 | customers = cursor.fetchall() 34 | 35 | if result > 0: 36 | customers_json = jsonify(customers) 37 | else: 38 | customers_json = 'No Customers in the Database' 39 | conn.close() 40 | return customers_json 41 | 42 | 43 | def add_state_census(name, pop,code): 44 | conn = open_connection() 45 | insert_sql = """INSERT INTO census_state_pop (statename, pop, code) 46 | VALUES (%s, %s, %s)""" 47 | with conn: 48 | cursor = conn.cursor() 49 | cursor.execute(insert_sql,(name,pop,code)) 50 | conn.commit() 51 | conn.close() 52 | return 53 | 54 | def new_census_data(): 55 | try: 56 | url = "https://api.census.gov/data/2010/dec/sf2?get=NAME,HCT001001&for=state:*" 57 | response = urlopen(url) 58 | response_data = json.loads(response.read()) 59 | return response_data 60 | 61 | except urllib.error.HTTPError as e: 62 | print(e.__dict__) 63 | except urllib.error.URLError as e: 64 | print(e.__dict__) 65 | 66 | 67 | def load_census_data(): 68 | response = new_census_data() 69 | conn = open_connection() 70 | insert_sql = """INSERT INTO census_state_pop (statename, pop, code) 71 | VALUES (%s, %s, %s)""" 72 | with conn: 73 | cursor = conn.cursor() 74 | for i, item in enumerate(response): 75 | if i > 0: 76 | name = item[0] 77 | pop = item[1] 78 | code = item[2] 79 | print('Name: ',name,' Population: ',pop, 'Code: ',code) 80 | cursor.execute(insert_sql,(name,pop,code)) 81 | conn.commit() 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /04_02/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | H Plus Sport Customers 4 | 5 | 6 | 17 |

H Plus Sport Customers

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% for row in data %} 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {% endfor %} 44 | 45 | 46 |
First NameLast NameEmailPhoneAddressCityStateZip
{{row["FirstName"]}}{{row["LastName"]}}{{row["Email"]}}{{row["Phone"]}}{{row["Address"]}}{{row["City"]}}{{row["State"]}}{{row["Zipcode"]}}
47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /04_02/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, request, render_template 2 | from db import get_customers, open_connection, load_census_data 3 | 4 | app = Flask(__name__) 5 | 6 | 7 | @app.route('/', methods=['GET']) 8 | def customers(): 9 | conn = open_connection() 10 | with conn.cursor() as cursor: 11 | sql = 'SELECT * FROM customers LIMIT 10;' 12 | result = cursor.execute(sql) 13 | customers = cursor.fetchall() 14 | 15 | return render_template('index.html', data=customers) 16 | 17 | @app.route('/states/') 18 | def states(): 19 | load_census_data() 20 | conn = open_connection() 21 | with conn.cursor() as cursor: 22 | sql = 'SELECT * FROM census_state_pop;' 23 | result = cursor.execute(sql) 24 | states = cursor.fetchall() 25 | return render_template('states.html', data=states) 26 | 27 | 28 | @app.route('/api/customers/') 29 | def customersJSON(): 30 | if request.method == 'POST': 31 | if not request.is_json: 32 | return jsonify({"msg":"Missing JSON in request"}), 400 33 | # Here I could add a function to add a customer 34 | return get_customers() 35 | 36 | 37 | if __name__ == '__main__': 38 | app.run() -------------------------------------------------------------------------------- /04_03/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SQLDemo 4 | // 5 | // Created by Nikiya Simpson on 7/28/21. 6 | // Copyright © 2021 Nikiya Simpson. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /04_03/Customer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Customer.swift 3 | // SQLDemo 4 | // 5 | // Created by Nikiya Simpson on 7/28/21. 6 | // Copyright © 2021 Nikiya Simpson. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class Customer 12 | { 13 | 14 | var firstname: String = "" 15 | var lastname: String = "" 16 | var email: String = "" 17 | var customerid: Int = 0 18 | 19 | 20 | init(customerid:Int,firstname:String, lastname:String,email:String) 21 | { 22 | self.customerid = customerid 23 | self.firstname = firstname 24 | self.lastname = lastname 25 | self.email = email 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /04_03/DBHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DBHelper.swift 3 | // SQLDemo 4 | // 5 | // Created by Nikiya Simpson on 7/28/21. 6 | // Copyright © 2021 Nikiya Simpson. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SQLite3 11 | 12 | class DBHelper 13 | { 14 | init() 15 | { 16 | db = openDatabase() 17 | createCustomerTable() 18 | } 19 | 20 | let dbPath: String = "hplussport.sqlite" 21 | var db:OpaquePointer? 22 | 23 | func openDatabase() -> OpaquePointer? 24 | { 25 | let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) 26 | .appendingPathComponent(dbPath) 27 | var db: OpaquePointer? = nil 28 | if sqlite3_open(fileURL.path, &db) != SQLITE_OK 29 | { 30 | print("error opening database") 31 | return nil 32 | } 33 | else 34 | { 35 | print("Successfully opened connection to database at \(dbPath)") 36 | return db 37 | } 38 | } 39 | 40 | func createCustomerTable() { 41 | 42 | let createCustomerSQL = "CREATE TABLE IF NOT EXISTS customers(CustomerID INTEGER PRIMARY KEY, FirstName TEXT, LastName TEXT,Email TEXT);" 43 | 44 | var createTableStatement: OpaquePointer? = nil 45 | if sqlite3_prepare_v2(db, createCustomerSQL, -1, &createTableStatement, nil) == SQLITE_OK 46 | { 47 | if sqlite3_step(createTableStatement) == SQLITE_DONE 48 | { 49 | print("Created customers table") 50 | } else { 51 | print("Not able to create customers table") 52 | } 53 | } else { 54 | print("CREATE TABLE statement did not run.") 55 | } 56 | sqlite3_finalize(createTableStatement) 57 | } 58 | 59 | 60 | func insert(customerid:Int, firstname:String, lastname:String, email:String) 61 | { 62 | let customers = read() 63 | for c in customers 64 | { 65 | if c.customerid == customerid 66 | { 67 | print("Customer in Database") 68 | return 69 | } 70 | } 71 | let insertCustomerString = "INSERT INTO customers(CustomerID, FirstName, LastName, Email) VALUES (?, ?, ?, ?);" 72 | var insertStatement: OpaquePointer? = nil 73 | if sqlite3_prepare_v2(db, insertCustomerString, -1, &insertStatement, nil) == SQLITE_OK { 74 | sqlite3_bind_int(insertStatement, 1, Int32(customerid)) 75 | sqlite3_bind_text(insertStatement, 2, (firstname as NSString).utf8String, -1, nil) 76 | sqlite3_bind_text(insertStatement, 3, (lastname as NSString).utf8String, -1, nil) 77 | sqlite3_bind_text(insertStatement, 4, (email as NSString).utf8String, -1, nil) 78 | 79 | if sqlite3_step(insertStatement) == SQLITE_DONE { 80 | print("Successfully inserted customer.") 81 | } else { 82 | print("Could not insert customer.") 83 | } 84 | } else { 85 | print("INSERT statement did not run.") 86 | } 87 | sqlite3_finalize(insertStatement) 88 | } 89 | 90 | func read() -> [Customer] { 91 | let queryStatementString = "SELECT CustomerID, FirstName, LastName, Email FROM customers;" 92 | var queryStatement: OpaquePointer? = nil 93 | var customers : [Customer] = [] 94 | if sqlite3_prepare_v2(db, queryStatementString, -1, &queryStatement, nil) == SQLITE_OK { 95 | while sqlite3_step(queryStatement) == SQLITE_ROW { 96 | let customerid = sqlite3_column_int(queryStatement, 0) 97 | let firstname = String(describing: String(cString: sqlite3_column_text(queryStatement, 1))) 98 | let lastname = String(describing: String(cString: sqlite3_column_text(queryStatement, 2))) 99 | let email = String(describing: String(cString: sqlite3_column_text(queryStatement, 3))) 100 | 101 | customers.append(Customer(customerid: Int(customerid), firstname: firstname, lastname: lastname, email:email)) 102 | //print("Query Result:") 103 | //print("\(customerid) | \(firstname) | \(lastname) | \(email)") 104 | } 105 | } else { 106 | print("SELECT statement did not run.") 107 | } 108 | sqlite3_finalize(queryStatement) 109 | return customers 110 | } 111 | 112 | func deleteByID(customerid:Int) { 113 | let deleteCustomerSQL = "DELETE FROM customers WHERE Customerid = ?;" 114 | var deleteStatement: OpaquePointer? = nil 115 | if sqlite3_prepare_v2(db, deleteCustomerSQL, -1, &deleteStatement, nil) == SQLITE_OK { 116 | sqlite3_bind_int(deleteStatement, 1, Int32(customerid)) 117 | if sqlite3_step(deleteStatement) == SQLITE_DONE { 118 | print("Successfully deleted customer.") 119 | } else { 120 | print("Could not delete customer.") 121 | } 122 | } else { 123 | print("DELETE statement did not run.") 124 | } 125 | sqlite3_finalize(deleteStatement) 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /04_03/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /04_03/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /04_03/README.md: -------------------------------------------------------------------------------- 1 | The code in this directory can be implemented using XCode. 2 | For a brief overview on a single page app for iPhone, visit: https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app 3 | 4 | For setting up a table view, check out this developer resource: https://developer.apple.com/tutorials/app-dev-training/setting-up-a-table-view 5 | 6 | -------------------------------------------------------------------------------- /04_03/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SQLDemo 4 | // 5 | // Created by Nikiya Simpson on 7/28/21. 6 | // Copyright © 2021 Nikiya Simpson. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 18 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 19 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 20 | guard let _ = (scene as? UIWindowScene) else { return } 21 | } 22 | 23 | func sceneDidDisconnect(_ scene: UIScene) { 24 | // Called as the scene is being released by the system. 25 | // This occurs shortly after the scene enters the background, or when its session is discarded. 26 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 27 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 28 | } 29 | 30 | func sceneDidBecomeActive(_ scene: UIScene) { 31 | // Called when the scene has moved from an inactive state to an active state. 32 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 33 | } 34 | 35 | func sceneWillResignActive(_ scene: UIScene) { 36 | // Called when the scene will move from an active state to an inactive state. 37 | // This may occur due to temporary interruptions (ex. an incoming phone call). 38 | } 39 | 40 | func sceneWillEnterForeground(_ scene: UIScene) { 41 | // Called as the scene transitions from the background to the foreground. 42 | // Use this method to undo the changes made on entering the background. 43 | } 44 | 45 | func sceneDidEnterBackground(_ scene: UIScene) { 46 | // Called as the scene transitions from the foreground to the background. 47 | // Use this method to save data, release shared resources, and store enough scene-specific state information 48 | // to restore the scene back to its current state. 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /04_03/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SQLDemo 4 | // 5 | // Created by Nikiya Simpson on 7/28/21. 6 | // Copyright © 2021 Nikiya Simpson. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 12 | 13 | 14 | @IBOutlet weak var customerTable : UITableView! 15 | 16 | let cellReuseIdentifier = "cell" 17 | 18 | var db:DBHelper = DBHelper() 19 | 20 | var customers:[Customer] = [] 21 | 22 | override func viewDidLoad() { 23 | super.viewDidLoad() 24 | customerTable.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) 25 | 26 | customerTable.delegate = self 27 | customerTable.dataSource = self 28 | 29 | db.insert(customerid: 1, firstname: "Nikiya Simpson", lastname:"Simpson", email:"ins@example.com") 30 | db.insert(customerid: 2, firstname: "John", lastname:"Smith", email:"js@example.com") 31 | db.insert(customerid: 3, firstname: "Jane", lastname:"Doe", email:"jd@example.com") 32 | 33 | customers = db.read() 34 | } 35 | 36 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 37 | { 38 | return customers.count 39 | 40 | } 41 | 42 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 43 | { 44 | let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) 45 | 46 | cell.textLabel?.text = customers[indexPath.row].firstname + " " + customers[indexPath.row].lastname + " Email: " + customers[indexPath.row].email 47 | 48 | return cell 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /04_04/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /04_04/create-tables.sql: -------------------------------------------------------------------------------- 1 | create table customers ( 2 | CustomerID INT NOT NULL, 3 | FirstName VARCHAR(255), 4 | LastName VARCHAR(255), 5 | Email VARCHAR(255), 6 | Phone VARCHAR(255), 7 | Address VARCHAR(255), 8 | City VARCHAR(255), 9 | State VARCHAR(255), 10 | Zipcode VARCHAR(255), 11 | PRIMARY KEY(CustomerID) 12 | ); 13 | 14 | create table census_state_pop ( 15 | statename VARCHAR(255), 16 | pop VARCHAR(255), 17 | code VARCHAR(255) 18 | ); -------------------------------------------------------------------------------- /04_04/db.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pymysql 3 | from flask import jsonify, request 4 | import json 5 | from urllib.request import urlopen 6 | import urllib.error 7 | 8 | db_user = os.environ.get('CLOUD_SQL_USERNAME') 9 | db_password = os.environ.get('CLOUD_SQL_PASSWORD') 10 | db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME') 11 | db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME') 12 | acs_api_key = os.environ.get('ACS_KEY') 13 | 14 | def open_connection(): 15 | unix_socket = '/cloudsql/{}'.format(db_connection_name) 16 | try: 17 | if os.environ.get('GAE_ENV') == 'standard': 18 | conn = pymysql.connect(user=db_user, password=db_password, 19 | unix_socket=unix_socket, db=db_name, 20 | cursorclass=pymysql.cursors.DictCursor 21 | ) 22 | except pymysql.MySQLError as e: 23 | print(e) 24 | 25 | return conn 26 | 27 | 28 | def get_customers(): 29 | conn = open_connection() 30 | with conn.cursor() as cursor: 31 | sql = 'SELECT * FROM customers LIMIT 50;' 32 | result = cursor.execute(sql) 33 | customers = cursor.fetchall() 34 | 35 | if result > 0: 36 | customers_json = jsonify(customers) 37 | else: 38 | customers_json = 'No Customers in the Database' 39 | conn.close() 40 | return customers_json 41 | 42 | 43 | def add_state_census(name, pop,code): 44 | conn = open_connection() 45 | insert_sql = """INSERT INTO census_state_pop (statename, pop, code) 46 | VALUES (%s, %s, %s)""" 47 | with conn: 48 | cursor = conn.cursor() 49 | cursor.execute(insert_sql,(name,pop,code)) 50 | conn.commit() 51 | conn.close() 52 | return 53 | 54 | def new_census_data(): 55 | try: 56 | url = "https://api.census.gov/data/2010/dec/sf2?get=NAME,HCT001001&for=state:*" 57 | response = urlopen(url) 58 | response_data = json.loads(response.read()) 59 | return response_data 60 | 61 | except urllib.error.HTTPError as e: 62 | print(e.__dict__) 63 | except urllib.error.URLError as e: 64 | print(e.__dict__) 65 | 66 | 67 | def load_census_data(): 68 | response = new_census_data() 69 | conn = open_connection() 70 | insert_sql = """INSERT INTO census_state_pop (statename, pop, code) 71 | VALUES (%s, %s, %s)""" 72 | with conn: 73 | cursor = conn.cursor() 74 | for i, item in enumerate(response): 75 | if i > 0: 76 | name = item[0] 77 | pop = item[1] 78 | code = item[2] 79 | print('Name: ',name,' Population: ',pop, 'Code: ',code) 80 | cursor.execute(insert_sql,(name,pop,code)) 81 | conn.commit() 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /04_04/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | H Plus Sport Customers 4 | 5 | 6 | 17 |

H Plus Sport Customers

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% for row in data %} 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {% endfor %} 44 | 45 | 46 |
First NameLast NameEmailPhoneAddressCityStateZip
{{row["FirstName"]}}{{row["LastName"]}}{{row["Email"]}}{{row["Phone"]}}{{row["Address"]}}{{row["City"]}}{{row["State"]}}{{row["Zipcode"]}}
47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /04_04/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, request, render_template 2 | from db import get_customers, open_connection, load_census_data 3 | 4 | app = Flask(__name__) 5 | 6 | 7 | @app.route('/', methods=['GET']) 8 | def customers(): 9 | conn = open_connection() 10 | with conn.cursor() as cursor: 11 | sql = 'SELECT * FROM customers LIMIT 10;' 12 | result = cursor.execute(sql) 13 | customers = cursor.fetchall() 14 | 15 | return render_template('index.html', data=customers) 16 | 17 | @app.route('/states/') 18 | def states(): 19 | load_census_data() 20 | conn = open_connection() 21 | with conn.cursor() as cursor: 22 | sql = 'SELECT * FROM census_state_pop;' 23 | result = cursor.execute(sql) 24 | states = cursor.fetchall() 25 | return render_template('states.html', data=states) 26 | 27 | 28 | @app.route('/api/customers/') 29 | def customersJSON(): 30 | if request.method == 'POST': 31 | if not request.is_json: 32 | return jsonify({"msg":"Missing JSON in request"}), 400 33 | # Here I could add a function to add a customer 34 | return get_customers() 35 | 36 | 37 | if __name__ == '__main__': 38 | app.run() -------------------------------------------------------------------------------- /04_04/states.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | H Plus Sport Customers 4 | 5 | 6 | 20 |

Census State Populations

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | {% for row in data %} 30 | 31 | 32 | 33 | 34 | {% endfor %} 35 | 36 | 37 |
State NamePopulation
{{row["statename"]}}{{row["pop"]}}
38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2021 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | Please note, this project may automatically load third party code from external 8 | repositories (for example, NPM modules, Composer packages, or other dependencies). 9 | If so, such third party code may be subject to other license terms than as set 10 | forth above. In addition, such third party code may also depend on and load 11 | multiple tiers of dependencies. Please review the applicable licenses of the 12 | additional dependencies. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Finding New Career Paths with SQL 2 | This is the repository for the LinkedIn Learning course Finding New Career Paths with SQL. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![Finding New Career Paths with SQL][lil-thumbnail-url] 5 | 6 | The SQL language is widely used and can be applied to a variety of technical fields such as data warehousing, application development, data science, and more. If you are familiar with SQL language or interested in learning more about it, join Nikiya Simpson in this course as she helps you design a career around this skillset, whether you are early in your career or if you are looking for a change. Nikiya explores different career areas and looks at specific examples of each so you know a little about what each entails before deciding to go down a particular path. If you’re wondering how to market your skills and discover where you can take your career using SQL knowledge you already have, join Nikiya in this course. 7 | 8 | ## Instructions 9 | This repository has folders for each of the videos in the course. 10 | 11 | ## Folders 12 | The folders are structured to correspond to the videos in the course. The naming convention is `CHAPTER#_MOVIE#`. As an example, the folder named `02_03` corresponds to the second chapter and the third video in that chapter. 13 | 14 | The [SQL Careers Assessment.pdf](https://github.com/LinkedInLearning/finding-new-career-paths-with-sql-2881262/blob/main/SQL%20Careers%20Assessment.pdf) document is a copy of the Assessment/Chapter Quiz you will take inside of the LinkedIn Learning video platform after the first chapter. The [Skills Inventory Worksheet.pdf](https://github.com/LinkedInLearning/finding-new-career-paths-with-sql-2881262/blob/main/Skills%20Inventory%20Worksheet.pdf) is for you to fill out while working through the course. 15 | 16 | ## Installing 17 | 1. To use these exercise files, you must have the following installed: 18 | - A Google Cloud Platform account. Some costs may apply if you do this. Otherwise, download mySQL on your local machine and create your own tables. 19 | - Python 3.8 on your local machine 20 | 2. Clone this repository into your local machine using the terminal (Mac), CMD (Windows), or a GUI tool like SourceTree. 21 | 22 | 23 | ### Instructor 24 | 25 | Nikiya Simpson 26 | 27 | 28 | 29 | 30 | 31 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/nikiya-simpson). 32 | 33 | [lil-course-url]: https://www.linkedin.com/learning/finding-new-career-paths-with-sql 34 | [lil-thumbnail-url]: https://cdn.lynda.com/course/2881262/2881262-1634842876132-16x9.jpg 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /SQL Careers Assessment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/finding-new-career-paths-with-sql-2881262/d7f802a1b7d573594824737c013fe1d4a0c83c83/SQL Careers Assessment.pdf -------------------------------------------------------------------------------- /Skills Inventory Worksheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/finding-new-career-paths-with-sql-2881262/d7f802a1b7d573594824737c013fe1d4a0c83c83/Skills Inventory Worksheet.pdf --------------------------------------------------------------------------------