“If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008...

29
If I can do it, If I can do it, ANYONE ANYONE can do it.” can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability Coordinator Carteret County Public Schools

Transcript of “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008...

Page 1: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

““If I can do it, If I can do it, ANYONEANYONE can do it.” can do it.”

Using MySQL in ABCToolsFebruary 12, 2008

NCDPI 2008 Accountability Conference

David J. MillushTesting & Accountability Coordinator

Carteret County Public Schools

Page 2: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

DISCLAIMERDISCLAIMERThe processes and procedures in this presentation have not been evaluated by the United States Food and Drug Administration or the North Carolina Department of Public Instruction and are not approved to diagnose, treat, cure, or prevent headaches in test coordinators. Although it has demonstrated some effectiveness in the elimination of bovine hoof fungus, the information provided in this presentation is for instructional purposes only and is not intended as a substitute for advice from your SQL programmer or other professional who actually knows what they are doing. You should consult with your RAC or other accountability professional before pulling your hair out, changing data, pretending you know what you are doing, or if you have or suspect you have figured out the North Carolina Accountability data collection and reporting process.

Page 3: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

MYSQL:MYSQL:

It has nothing to do with birds.

Page 4: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

OBJECTIVESOBJECTIVES

• Introduce the SQL elements needed for queries in ABCTools08

• Demonstrate common SQL query structure

• Relieve fear of MySQL tab in ABCTools08

• Encourage your experimentation with SQL

Page 5: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

KEY REFERENCESKEY REFERENCESMySQL 5.1 Reference ManualMySQL 5.1 Reference Manual http://dev.mysql.com/doc/refman/5.0/en/

W3Schools' Online SQL TutorialW3Schools' Online SQL Tutorial http://www.w3schools.com/sql/

ABCTools 2008 Training ManualABCTools 2008 Training Manual https://www.rep.dpi.state.nc.us/abctools08/

Accountability Database / LibraryAccountability Database / Library https://www.rep.dpi.state.nc.us/adb/ (Table Format Browser)

Page 6: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

MYSQL: WHAT IS IT?MYSQL: WHAT IS IT?

• Database management system

• Stores data in separate tables

• Uses Structured Query Language (SQL)

• MySQL is the database server software.

• SQL is the language used to interact with MySQL.

Page 7: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

IMPORTANT RULES!!!IMPORTANT RULES!!!

1.Try it. It doesn’t hurt.

2.You can’t break anything with a query.

3.You can’t break anything with a query.

Page 8: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

GRAMMAR COUNTSGRAMMAR COUNTS

Like your English Composition teacher:Like your English Composition teacher:

• SQL requires good grammar;

• SQL requires proper syntax and punctuation;

• MySQL expects you to have well thought-out statements;

• SQL is easy to understand… when you pay attention;

• MySQL tells you when corrections are required;

• MySQL rewards you for your effort;

• SQL doesn’t require more from you than you can handle.

Page 9: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION BASICSPUNCTUATION BASICS

Simple, but essential rules:Simple, but essential rules:

•Commas separate all fields / elements in a query list.•Apostrophes enclose all field contents.

•Parentheses enclose statement groups.

•An asterisk ( * ) means “everything.”

•A percent sign ( % ) means “anything.”

•Keyboard math symbols are routinely used.

Page 10: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION CONT’DPUNCTUATION CONT’D

Commas separate all fields and elements.Commas separate all fields and elements.

For example:

SELECT school_code, collection_code, student_id, or

… and englrsncd not in ('E','G','J','P','Q','S','V‘) …

Page 11: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION CONT’DPUNCTUATION CONT’D

Apostrophes enclose all field contentsApostrophes enclose all field contents

For example:

… WHERE (grade = '09' and ma08score < '321' and (compscore < '100' or compscore is null) …

or

… and englrsncd not in ('E’, ‘G’, ‘J’, ‘P’, ‘Q’, ‘S’) …

Page 12: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION CONT’DPUNCTUATION CONT’D

Parentheses enclose statement groupsParentheses enclose statement groupsFor example:

… or (grade = '09' and ma08score < '321' ) and

(compscore < '100' or compscore is null) …

or

… WHERE ( (a.2006_ID = b.2005_ID) or

((a.2006_last = b.2005_last) and (a.2006_first =

b.2005_first) and (a.2006_dob = b.2005_dob)) )

Page 13: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION CONT’DPUNCTUATION CONT’D

An asterisk ( * ) means “An asterisk ( * ) means “everythingeverything.”.”For example:

SELECT * from accdata where collection_code = ‘FDF’

A percent sign ( % ) means “A percent sign ( % ) means “anythinganything.”.”For example:

SELECT * from accdemo where last_name LIKE ‘%Hallor%’

Page 14: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

PUNCTUATION CONT’DPUNCTUATION CONT’D

Keyboard math symbols are routinely used.Keyboard math symbols are routinely used.

For example:

… L.reporting_year = '2007' and L.collection_code = 'FDS' and D.reporting_year = '2007' and D.collection_code != 'FDS' and H.test_date > '20060730' and H.test_date <= '20070801’ …

Page 15: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

WHO? WHAT? WHEN? WHO? WHAT? WHEN?

Start with simple questions:Start with simple questions:

• What do you want reported?

• What table(s) contains the information?

• What restrictions need to apply?

• How should the results be sorted?

(SELECT) (SELECT)

(FROM)(FROM)

(WHERE)(WHERE)

(ORDER BY)(ORDER BY)

Page 16: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

SELECT =SELECT =

• SELECT statement starts routine queriesSELECT statement starts routine queries

• SELECT determines what will be displayedSELECT determines what will be displayed

• SELECT is followed by the name of the fields you SELECT is followed by the name of the fields you want displayed want displayed

• Must use the exact field names from the table Must use the exact field names from the table

• The order of the SELECT statement creates the The order of the SELECT statement creates the order fields are displayed in the output (report)order fields are displayed in the output (report)

WhatWhat

Page 17: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

SELECTSELECT

•Start with SELECT and then add Start with SELECT and then add fields to be displayedfields to be displayed

• Fields are separated by commasFields are separated by commasFor example:

SELECT school_code, collection_code, student_id

Or

SELECT *

Page 18: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

FROM =FROM =• After SELECT statement, add After SELECT statement, add FROMFROM statement statement• FROMFROM identifies the table(s) where the desired data identifies the table(s) where the desired data

is recordedis recorded

• Multiple tables in the Multiple tables in the FROMFROM statement creates a statement creates a “inner join” of the tables… this is slightly more “inner join” of the tables… this is slightly more complex coding and requires specification with the complex coding and requires specification with the SELECT, WHERE, and ORDER BY statements SELECT, WHERE, and ORDER BY statements

• Must use the exact table namesMust use the exact table names

WhereWhere

Page 19: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

FROMFROMFROMFROM follows immediately after the follows immediately after the last field in the SELECT statementlast field in the SELECT statement

For example:

SELECT school_code, collection_code, student_id, grade, dob FROM accdemo

or

SELECT L.collection_code, L.school_code, D.last_name, D.student_id, D.test_date FROM accdemo L, acchist D

Page 20: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

WHERE =WHERE =

After FROM statement, add After FROM statement, add WHEREWHERE• WHERE sets the limits or conditions on the data

being queried• WHERE subsets the data

• WHERE statements are field names with a qualifying indicator and the limits

• Add additional field names to the WHERE statement with AND or OR

If… kind ofIf… kind of

Page 21: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

WHEREWHERE

• Plan your WHERE statements based on the results desired

• Group WHERE elements in parentheses

• Priority order of elements may alter the output 2 X 10 + .95 = 20.95 or 2(10 + .95) = 21.90

• If the output is questionable, rethink your WHERE statement

““Abouts”Abouts”

Page 22: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

WHEREWHERE

WHEREWHERE follows the FROM statement follows the FROM statement

For example:

SELECT school_code, collection_code, student_id, grade, dob FROM accdemo WHERE grade = ‘09’ AND school_code = ‘160312’ OR school_code = ‘160313’

Or…

Page 23: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

WHEREWHERESELECT DISTINCT h.student_id, h.reporting_year, h.collection_code, h.school_code, h.last_name, h.first_name, h.grade, h.i_path, a.date_enter_hs, h.ctamrsncd, h.ctamscore, h.ma08rsncd, h.ma08score, h.ma08level, h.alg1rsncd, h.alg1score, h.alg1level,h.ctarrsncd, h.ctarscore, h.rd08rsncd, h.rd08score, h.rd08level, h.englrsncd, h.englscore, h.engllevel FROM histaudit h, accdemo a WHERE ((h.collection_code = a.collection_code) and h.collection_code = 'FDF') and (h.student_id = a.student_id) and (a.date_enter_hs is null or a.date_enter_hs < '20060616') and (h.i_path is null or (h.i_path != 'OCC'and h.i_path != 'GNRL')) and h.grade in ('9','10','11','12') and ((h.ctamscore is null or h.ctamscore != 'P') and (h.ma08score is null or h.ma08score < '321') and ((h.alg1score is null or (h.alg1score BETWEEN '21' and '50') or (h.alg1score BETWEEN '115' and '144')))) OR ((h.collection_code = a.collection_code) and h.collection_code = 'FDF') and (h.student_id = a.student_id) and (a.date_enter_hs is null or a.date_enter_hs < '20060616') and (h.i_path is null or (h.i_path != 'OCC' and h.i_path !='GNRL')) and h.grade in ('9','10','11','12') and ((h.ctarscore is null or h.ctarscore != 'P') and ((h.rd08score is null or h.rd08score < '254') and (h.ma08score is null or h.ma08score < '321')) and (h.englscore is null or (h.englscore BETWEEN '18' and '48') or (h.englscore BETWEEN '120' and '142')))

Page 24: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

ORDER BY = ORDER BY =

SortSortAfter WHERE statement, add After WHERE statement, add ORDER BYORDER BY

• ORDER BY organizes data in the same manner as sorting data in an Excel spreadsheet

• ORDER BY sort elements are field names

• Use commas to separate ORDER BY elements

For example:

… FROM histaudit WHERE grade = 10 and i_path != 'GNRL' and ((engllevel is NULL and (englrsncd is NULL or englrsncd not in ('E','G','J','P','Q','S','V'))) or (alg1level is NULL and (alg1rsncd is NULL or alg1rsncd not in ('E','G','J','P','Q','S','V')))) and collection_code = 'FDF' ORDER BY school_code, last_name, first_name

Page 25: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

NICE-TO-KNOWSNICE-TO-KNOWS

• IS NULL is not the same as zero

• != means “not equal”

• ‘09’ is not the same as ‘9’

• Use LIKE and % when you aren’t sure:…WHERE last_name LIKE ‘%Hallor%’

• Write your queries in Notepad so you can see them. Copy and paste into ABCTOOLS08 MySQL tab to run.

• Cut and paste from queries that work.

• Use a scratch pad to outline your search criteria, then construct the SQL query. Run it and then modify until you get what you need.

Page 26: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.
Page 27: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

COMPUTER SKILLS FAILED OR NOT TAKENCOMPUTER SKILLS FAILED OR NOT TAKEN

SELECT DISTINCT student_id, reporting_year, collection_code, school_code, grade, last_name, first_name, cspfrsncd, cspfscore, cscmrsncd, cscmscore, comprsncd, complevel, i_path, ma08score, ma08rsncdFROM histaudit WHERE collection_code = 'NOV ' and (grade in ('9','09','10','11','12') and i_path is null or i_path != 'GNRL') and (complevel is null or complevel = '2') and ((cspfrsncd is null or (cspfrsncd != 'J' and cspfrsncd != 'K' and cspfrsncd != 'E' )) or (cscmrsncd is null or (cscmrsncd != 'J' and cscmrsncd != 'K' and cscmrsncd != 'E'))) ORDER BY school_code, grade, last_name, first_name

Page 28: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.
Page 29: “If I can do it, ANYONE can do it.” Using MySQL in ABCTools February 12, 2008 NCDPI 2008 Accountability Conference David J. Millush Testing & Accountability.

““Test everything. Hold on to what is good.” Test everything. Hold on to what is good.”

1 Thessalonians 5:211 Thessalonians 5:21

David J. MillushTesting & Accountability Coordinator

Carteret County Public Schools

[email protected]

Phone: 252-728-4583 ext. 111