Marketing Analytics: Database Query with MySQL Disclaimer: All logos, photos, etc. used in this presentation are the property of their respective copyright.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

Computer Concepts BASICS 4th Edition
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Concepts of Database Management Seventh Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
Database Applications – Microsoft Access Lesson 9 Designing Special Queries Updated 4/11.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
1 By: Nour Hilal. Microsoft Access is a database software where data is stored in one or more Tables. A Database is a group of related Tables. Access.
® Microsoft Office 2010 Access Tutorial 3 Maintaining and Querying a Database.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Microsoft Office XP Illustrated Introductory, Enhanced Tables and Queries Using.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Lesson 13 Databases Unit 2—Using the Computer. Computer Concepts BASICS - 22 Objectives Define the purpose and function of database software. Identify.
Microsoft Access Database Creation and Management.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
3 A Guide to MySQL.
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Databases.
Chapter 5 Introduction to SQL.
Database application MySQL Database and PhpMyAdmin
SQL FUNDAMENTALS CDSE Days 2018.
Chapter 7 Working with Databases and MySQL
Structured Query Language
Chapter 8 Working with Databases and MySQL
Creating and Modifying Queries
Data Visualization with Tableau
Access: SQL Participation Project
CS122 Using Relational Databases and SQL
Navya Thum January 30, 2013 Day 5: MICROSOFT EXCEL Navya Thum January 30, 2013.
CS1222 Using Relational Databases and SQL
Access Test Questions Test Date: 05/05/16.
Shelly Cashman: Microsoft Access 2016
CS122 Using Relational Databases and SQL
Presentation transcript:

Marketing Analytics: Database Query with MySQL Disclaimer: All logos, photos, etc. used in this presentation are the property of their respective copyright owners and are used here for educational purposes only © Stephan Sorger Database Query with MySQL; SQL.1www.StephanSorger.com

CategoryDescription IntroductionOverview of database query languages RDBMSExample of Relational Database Management System HostingObtaining hosting server for MySQL (free or paid) SetupSetting up the MySQL Server on hosting platforms ImportImporting databases into MySQL Server StructureData structure; Showing tables within databases SHOWCommands to display data SELECTCommands to choose certain pieces of data SortingCommands to sort data FilteringCommands to filter data LogicalUsing logical commands (AND, OR) in commands CreatingCreating, Dropping, and Altering databases and tables Outline © Stephan Sorger Database Query with MySQL; SQL.2www.StephanSorger.com

CategoryDescription SQLStructured Query Language Programming language for accessing RDBMS RDBMSRelational Database Management System SQLConsists of two items: Data Definition Language: Syntax for defining data structures Data Manipulation Language: Syntax for selecting, inserting deleting, and updating data in databases Top 3Top 3 Database engines: Oracle MySQL Microsoft SQL Server MySQLOpen source; Free; Available for Mac and PC Manual: See dev.mysql.com/doc/index.html Database Query: Introduction © Stephan Sorger Database Query with MySQL; SQL.3www.StephanSorger.com

RDBMS Database Example Row: Record Primary Key: Column with 100% unique entries similar to Social Security Number (‘Engine’ column will not work; duplicate entries) © Stephan Sorger Database Query with MySQL; SQL.4www.StephanSorger.com

MySQL: Hosting Go to 000webhost.com (or other similar Web hosting service) and get an account © Stephan Sorger Database Query with MySQL; SQL.5www.StephanSorger.com

MySQL Server: Setup Creating MySQL Databases for hosting accounts on GoDaddy.com © Stephan Sorger Database Query with MySQL; SQL.6www.StephanSorger.com

For GoDaddy, launch hosting account to see cPanel (shown). Click on MySQL Database Wizard MySQL: Server Setup © Stephan Sorger Database Query with MySQL; SQL.7www.StephanSorger.com

MySQL Server: Setup Enter name for database © Stephan Sorger Database Query with MySQL; SQL.8www.StephanSorger.com

MySQL Server: Setup Enter username and password © Stephan Sorger Database Query with MySQL; SQL.9www.StephanSorger.com

MySQL Server: Setup Select privileges for user © Stephan Sorger Database Query with MySQL; SQL.10www.StephanSorger.com

MySQL Server: Setup Select phpMyAdmin © Stephan Sorger Database Query with MySQL; SQL.11www.StephanSorger.com

MySQL: Importing Databases Select your Database (Database1) © Stephan Sorger Database Query with MySQL; SQL.12www.StephanSorger.com

MySQL: Importing Databases Select Import © Stephan Sorger Database Query with MySQL; SQL.13www.StephanSorger.com

MySQL: Importing Databases MySQL Sample Databases: dev.mysql.com/doc/index-other.html © Stephan Sorger Database Query with MySQL; SQL.14www.StephanSorger.com

MySQL: Importing Databases Choose File: Dataset: world.sql Click “Go” (bottom of page) © Stephan Sorger Database Query with MySQL; SQL.15www.StephanSorger.com

MySQL: Importing Databases Imported OK; Click “Database1” © Stephan Sorger Database Query with MySQL; SQL.16www.StephanSorger.com

MySQL: Data Structure Check “City” Table within World database Click on SQL tab © Stephan Sorger Database Query with MySQL; SQL.17www.StephanSorger.com

MySQL: Data Structure In SQL tab, enter “SHOW DATABASES” and hit “Go” SQL commands also called “queries” are in ALL CAPS Table entries are in lower case or Mixed Case © Stephan Sorger Database Query with MySQL; SQL.18www.StephanSorger.com

MySQL: Data Structure Shows databases: information_schema (already in SQL server) Database1 (we created) © Stephan Sorger Database Query with MySQL; SQL.19www.StephanSorger.com

MySQL: Data Structure In SQL tab, enter “SHOW TABLES” and hit “Go” © Stephan Sorger Database Query with MySQL; SQL.20www.StephanSorger.com

MySQL: Data Structure Tables: City Country Country Language © Stephan Sorger Database Query with MySQL; SQL.21www.StephanSorger.com

MySQL: SHOW Commands View columns of table Click on SQL tab Syntax: SHOW COLUMNS FROM (table) Here: SHOW COLUMNS FROM City Then click Go © Stephan Sorger Database Query with MySQL; SQL.22www.StephanSorger.com

MySQL: SHOW Commands Results: See columns from table Note PRI (primary) key Here, PRI = ID field © Stephan Sorger Database Query with MySQL; SQL.23www.StephanSorger.com

MySQL: SHOW Commands Click on file structure list in left column to see table Here, click on “City” © Stephan Sorger Database Query with MySQL; SQL.24www.StephanSorger.com

MySQL: SELECT Commands SELECT Name FROM City and click Go Note column names on right Note commands on bottom © Stephan Sorger Database Query with MySQL; SQL.25www.StephanSorger.com

MySQL: SELECT Commands Result: Names of cities © Stephan Sorger Database Query with MySQL; SQL.26www.StephanSorger.com

MySQL: SELECT Commands Select multiple columns from tables using comma (,) between column labels Note semicolon at end of line (most compilers will run command without semicolon if command is only 1 line) SELECT Name, CountryCode FROM City; © Stephan Sorger Database Query with MySQL; SQL.27www.StephanSorger.com

MySQL: SELECT Commands Result: Names of cities AND Names of Country Codes © Stephan Sorger Database Query with MySQL; SQL.28www.StephanSorger.com

MySQL: SELECT Commands Insert wildcard character (*) to retrieve all information SELECT * FROM City © Stephan Sorger Database Query with MySQL; SQL.29www.StephanSorger.com

MySQL: SELECT Commands Result: Entire dataset © Stephan Sorger Database Query with MySQL; SQL.30www.StephanSorger.com

MySQL: SELECT with Distinct and LIMIT DISTINCT: To show only one instance of a particular value SELECT DISTINCT CountryCode FROM City © Stephan Sorger Database Query with MySQL; SQL.31www.StephanSorger.com

Result: Distinct country codes MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.32www.StephanSorger.com

Show only first 5 using LIMIT command SELECT Name, CountryCode FROM City LIMIT 5 MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.33www.StephanSorger.com

Result: First 5 entries MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.34www.StephanSorger.com

Select only limited set of entries From start point (say, 5) To a certain number of data points (say, 10) (Computers start counting at 0, not at 1, so results will show “6”, not “5” SELECT Name, CountryCode FROM City LIMIT 5, 10 MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.35www.StephanSorger.com

Result: Results MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.36www.StephanSorger.com

Fully Qualified Names: “dataset.label” Handy if working on multiple databases with the same column SELECT City.Name FROM City MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.37www.StephanSorger.com

Results: Same as before Note names in order as found in the original table; Can be confusing. Alternative: Sort. MySQL: SELECT with Distinct and LIMIT © Stephan Sorger Database Query with MySQL; SQL.38www.StephanSorger.com

MySQL: Sorting Sort results using ORDER BY command SELECT Name FROM City ORDER BY Name © Stephan Sorger Database Query with MySQL; SQL.39www.StephanSorger.com

MySQL: Sorting Results are now in alphabetic order © Stephan Sorger Database Query with MySQL; SQL.40www.StephanSorger.com

MySQL: Sorting Sorting multiple columns, specifying order parameter SELECT Name, CountryCode, District FROM City ORDER BY Name © Stephan Sorger Database Query with MySQL; SQL.41www.StephanSorger.com

MySQL: Sorting Results: Multiple columns, sorted by Name © Stephan Sorger Database Query with MySQL; SQL.42www.StephanSorger.com

MySQL: Sorting Sequential Sort: Sort by x, then by y SELECT Name,CountryCode,District from City ORDER BY name,CountryCode © Stephan Sorger Database Query with MySQL; SQL.43www.StephanSorger.com

MySQL: Sorting Result: Sort by Name, then by Country Code (not very interesting in this case, because data is unique for each area) © Stephan Sorger Database Query with MySQL; SQL.44www.StephanSorger.com

MySQL: Sorting Sorting in reverse direction; from high to low DESC = Descending ASC = Ascending SELECT Name, CountryCode FROM City ORDER BY Name DESC © Stephan Sorger Database Query with MySQL; SQL.45www.StephanSorger.com

MySQL: Sorting Result: Names from Z – A BUT: Algorithm lists special characters, such as umlauted vowels, AFTER Z © Stephan Sorger Database Query with MySQL; SQL.46www.StephanSorger.com

MySQL: Sorting Select highest value (or lowest value) SELECT Name, Population FROM City ORDER BY Population LIMIT 1 © Stephan Sorger Database Query with MySQL; SQL.47www.StephanSorger.com

MySQL: Sorting Results: Adamstown has the smallest population, with only 42 people © Stephan Sorger Database Query with MySQL; SQL.48www.StephanSorger.com

MySQL: Sorting Select highest value (or lowest value) SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 1 © Stephan Sorger Database Query with MySQL; SQL.49www.StephanSorger.com

MySQL: Sorting Results: Mubai has the largest population, with 10,500,000 people © Stephan Sorger Database Query with MySQL; SQL.50www.StephanSorger.com

MySQL: Filtering Filtering: Want only areas within country code ‘AFG’ SELECT Name, CountryCode FROM City WHERE CountryCode=‘AFG’ © Stephan Sorger Database Query with MySQL; SQL.51www.StephanSorger.com

MySQL: Filtering Results © Stephan Sorger Database Query with MySQL; SQL.52www.StephanSorger.com

MySQL: Filtering Filtering: Want to list “small cities”, i.e. areas with population under 10,000 SELECT Name, Population FROM City WHERE Population <= (could also show “large cities”) : SELECT Name, Population FROM City WHERE Population >= © Stephan Sorger Database Query with MySQL; SQL.53www.StephanSorger.com

MySQL: Filtering Result: Listing of “small” cities in ID order (could also sort if desired) © Stephan Sorger Database Query with MySQL; SQL.54www.StephanSorger.com

MySQL: Filtering Filtering: Want to list “medium cities” i.e. areas with population between 10,000 and 50,000: SELECT Name, Population FROM City WHERE Population BETWEEN AND OR SELECT Name, Population FROM City WHERE Population >= && Population <= © Stephan Sorger Database Query with MySQL; SQL.55www.StephanSorger.com

MySQL: Filtering Result: “Sweet spot” cities between 10,000 and 50,000 © Stephan Sorger Database Query with MySQL; SQL.56www.StephanSorger.com

MySQL: Logical Operators Find name of city within AFG with a population greater than 200,000 SELECT Name, CountryCode FROM City WHERE CountryCode=‘AFG’ AND Population> © Stephan Sorger Database Query with MySQL; SQL.57www.StephanSorger.com

MySQL: Logical Operators Result: Two cities met both criteria © Stephan Sorger Database Query with MySQL; SQL.58www.StephanSorger.com

MySQL: Logical Operators Find name of city within NLD OR with a population greater than 400,000 SELECT Name, CountryCode, Population FROM City WHERE CountryCode=‘NLD’ AND Population> © Stephan Sorger Database Query with MySQL; SQL.59www.StephanSorger.com

MySQL Server Result: Three cities met at least one of the criteria © Stephan Sorger Database Query with MySQL; SQL.60www.StephanSorger.com

MySQL: Searching Use REGEXP (regular expression) to search for item. Here, we want to search for any district with the word “Holland” in it. SELECT Name, District FROM City WHERE District REGEXP 'Holland ' © Stephan Sorger Database Query with MySQL; SQL.61www.StephanSorger.com

MySQL: Searching Results: Many districts have the word “Holland” in them © Stephan Sorger Database Query with MySQL; SQL.62www.StephanSorger.com

MySQL: Special Columns Create special columns using math: +, -, *, / For example, what if population were to grow by 10%? SELECT Name, Population, Population*1.1 AS Population_Growth FROM City © Stephan Sorger Database Query with MySQL; SQL.63www.StephanSorger.com

MySQL: Special Columns Result: Special Column temporarily inserted in database: Population Growth Shows population + 10% SELECT Name, Population, Population*1.1 AS Population_Growth FROM City © Stephan Sorger Database Query with MySQL; SQL.64www.StephanSorger.com

MySQL: Create Database Create new database called “database2” CREATE DATABASE database2 To delete database: DROP DATABASE database2 © Stephan Sorger Database Query with MySQL; SQL.65www.StephanSorger.com

MySQL: Create Table Create new table through phpMyAdmin By clicking on Database © Stephan Sorger Database Query with MySQL; SQL.66www.StephanSorger.com

MySQL: Create Table Within phpMyAdmin: Create table: Enter Name Enter number of columns © Stephan Sorger Database Query with MySQL; SQL.67www.StephanSorger.com

MySQL: Create Table Within MySQL: Create new table: CREATE Drop or rename table: DROP TABLE signup RENAME TABLE signup TO users Create new table for website where people can sign up for s CREATE TABLE signup (  Open bracket; Create new lines id int NOT NULL AUTO_INCREMENT  First variable: id; data type: Integer; Automatically add 1 name varchar (30) NOT NULL  Second variable: name; alphanumeric text; Required varchar (30) NOT NULL  Third variable: ; max length: 30 char. ; Required PRIMARY KEY (id)  Declare primary key; in this case, “id” )  Close bracket © Stephan Sorger Database Query with MySQL; SQL.68www.StephanSorger.com

MySQL: Create Table Click on Structure to see table structure id underlined PRIMARY KEY © Stephan Sorger Database Query with MySQL; SQL.69www.StephanSorger.com

MySQL: Create Table Manually enter data by clicking Insert tab, then click Go © Stephan Sorger Database Query with MySQL; SQL.70www.StephanSorger.com

MySQL Server Results: -Data inserted -ID incremented To Delete a Row: DELETE FROM signup WHERE name = ‘Kathy Kar’ © Stephan Sorger Database Query with MySQL; SQL.71www.StephanSorger.com

MySQL: Alter Table Add column: phone (phone number) To add a column: ALTER TABLE signup ADD phone varchar(10) NOT NULL To delete a column: ALTER TABLE signup DROP COLUMN phone © Stephan Sorger Database Query with MySQL; SQL.72www.StephanSorger.com

MySQL Server Results: New column inserted: “phone” © Stephan Sorger Database Query with MySQL; SQL.73www.StephanSorger.com

MySQL: Reference Manuals To learn all commands, functions, etc. available, go to: dev.mysql.com/doc/index.html © Stephan Sorger Database Query with MySQL; SQL.74www.StephanSorger.com