An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A....
-
Upload
isaac-ryan -
Category
Documents
-
view
225 -
download
0
Transcript of An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A....
![Page 1: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/1.jpg)
An Intro to Writing SQL Queries &
Using the sqlReports Customization for PowerSchool
Chris A. McManigalCamden County SchoolsKingsland, GA
![Page 2: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/2.jpg)
GaETC App
![Page 3: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/3.jpg)
Session Evaluation
![Page 4: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/4.jpg)
Vendors• Please make sure to visit the Vendors Room in Kenyan ½
• Vendors will be here all day Tuesday
![Page 5: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/5.jpg)
Overview• Basic database architecture
• SQL Query Tools
• SQL definitions and structure
• SQL functions
• What are sqlReports?
• Downloading/Installing sqlReports
• Creating an sqlReport
• Importing/Exporting sqlReports
• Q & A
![Page 6: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/6.jpg)
Database architecture
![Page 7: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/7.jpg)
Database table
ID Last_name First_name Gender Ethnicity Grade_Level
1 Smith John M W 2
2 Brown Jim M B 3
3 Jones Sue F H 2
4 Smith Betty F A 4
FIELDS (COLUMNS)
RECORDS (ROWS)
![Page 8: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/8.jpg)
PowerSchool Tables/Guides• Data dictionary contains all tables and fields within each table
(Data Dictionary Tables for PowerSchool 7.x)
• Custom fields API guide provides functions to quickly access various tables’ custom fields (PS_CUSTOMFIELDS API Guide for PowerSchool 7.x)
![Page 9: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/9.jpg)
SQL Query Tools• Oracle comes with SQL *Plus• Command-line interface• Cannot edit and resubmit; must retype• Mainly used for scripted queries
• Many GUI/IDE query tools• Show database layout (tables, views, columns, etc.)• Color coding of keywords and formatting for easier readability • Editing for trial-and-error querying• Display results on same page• Saving of SQL queries• Exporting of results in various formats (.xls, .txt, .xml, etc.)• Examples: Oracle SQL Developer, RazorSQL, Advanced Query Tool,
Aqua Data Studio
![Page 10: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/10.jpg)
SQL Developer• Download from oracle.com• Must register• Must have Java Development Kit installed• SQL Developer comes with or without JDK
• Database connection• Need DB server IP address• Need password for one of the PS users (ps, psnavigator,
psdataminer)• No need to create separate ODBC connection
![Page 11: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/11.jpg)
What is SQL??• Structured Query Language
• Standard language structure used to access and manipulate relational databases
• Many different “flavors” depending on type of database; Oracle uses PL/SQL
![Page 12: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/12.jpg)
Parts of the SQL query• SELECT statement
• Declares the fields to be returned by the query• ‘*’ returns all fields
• FROM clause• Defines the table being queried• Can contain JOIN clauses to query multiple tables
• WHERE clause• Provides constraints on the records to be returned
• GROUP BY clause• Eliminates duplication and provides for using aggregate functions
• HAVING clause• Provides constraints on items in a GROUP BY clause, including aggregate functions
• ORDER BY clause• Sorts the records that are returned
![Page 13: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/13.jpg)
Comparison OperatorsOperator Description
= Equality test
<> Inequality test
> Greater than test
< Less than test
>= Greater than or equal to test
<= Less than or equal to test
IN “Equivalent to any member”test
BETWEEN Inclusive range test
LIKE Character pattern-matching test
IS NULL Null (empty) test
![Page 14: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/14.jpg)
Logical OperatorsOperator Description
AND All constraints must be TRUE
OR At least one of the constraints must be TRUE
NOT The constraint must be FALSE
![Page 15: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/15.jpg)
SELECT & FROM
SELECT *FROM students
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM students
SELECT course_number, section_number FROM cc
![Page 16: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/16.jpg)
DISTINCT
• Selects distinct rows from a table
SELECT DISTINCT last_name FROM students
SELECT DISTINCT course_number, course_nameFROM storedgrades
![Page 17: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/17.jpg)
WHERESELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’
![Page 18: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/18.jpg)
WHERE (cont.)SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND (grade_level = 3 OR
grade_level = 4 OR grade_level = 5)
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND grade_level IN (3,4,5)
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND grade_level >= 3
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND grade_level BETWEEN 3 AND 5
![Page 19: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/19.jpg)
ORDER BYSELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND grade_level IN (3,4,5) ORDER BY grade_level
SELECT schoolid, student_number, grade_level, gender, ethnicity FROM studentsWHERE schoolid = 100 AND gender = ‘F’ AND grade_level IN (3,4,5) ORDER BY grade_level,student_number
![Page 20: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/20.jpg)
LIKE & Wildcards• Wildcards• ‘%’ (percent)
• substitute for one or more characters• ‘_’ (underscore)
• Substitute for exactly one character
SELECT course_number, course_nameFROM coursesWHERE course_number LIKE ‘00%’
SELECT course_number, course_nameFROM coursesWHERE course_number LIKE ’_ _1%’ (note: underscores separated by space for clarity only; do NOT separate with space in query)
![Page 21: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/21.jpg)
SQL Aliases• Used for• Specifying the output column names• Abbreviating table names
SELECT s.lastfirst “Student”, s.home_room “Teacher”FROM students s
![Page 22: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/22.jpg)
JOIN• Used to link multiple tables based on the relationship between certain columns
(called “keys”)
• JOIN notation• Explicit
• Uses SQL keywords JOIN and ON
SELECT s.lastfirst,s g.course_name, sg.gradeFROM students s JOIN storedgrades sg ON sg.studentid = s.id
• Implicit• Lists the tables separated by commas and the WHERE clause provides additional constraints
SELECT s.lastfirst, sg.course_name, sg.gradeFROM students s, storedgrades sgWHERE s.id = sg.studentid
![Page 23: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/23.jpg)
JOIN Types• Types• INNER JOIN
• Returns records when there is at least one match between tables• LEFT JOIN
• Returns records from the left table regardless of matches in other table
• RIGHT JOIN• Returns records from the right table regardless of matches in other
table• FULL JOIN
• Combines LEFT and RIGHT JOINs• Returns records for both tables regardless of matches in other table
• Self-Join• Joins a table to itself
![Page 24: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/24.jpg)
INNER JOINSELECT hr.levelvalue, s.lastfirst, s.grade_levelFROM honorroll hrJOIN students s ON s.id = hr.studentidWHERE hr.yearid = 20 AND hr.storecode = ‘Q1’ORDER BY hr.levelvalue, s.lastfirst
SELECT s.schoolid, t.lastfirst, s.lastfirstFROM students s JOIN cc ON cc.studentid = s.id AND cc.termid = 2000 AND cc.course_number LIKE ‘00%’ AND cc.expression LIKE ‘1(%’JOIN teachers t ON cc.teacherid = t.idWHERE s.enroll_status = 0ORDER BY s.schoolid, t.lastfirst, s.lastfirst
![Page 25: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/25.jpg)
LEFT JOINSELECT s.grade_level, s.lastfirst, hr.levelvalueFROM students s LEFT JOIN honorroll hr ON s.id = hr.studentid AND hr.yearid = 20 AND hr.storecode = ‘Q1’ORDER BY s.grade_level, s.lastfirst
SELECT s.grade_level, s.lastfirst, sg.percentFROM students sLEFT JOIN storedgrades sg ON sg.studentid = s.id AND sg.percent < 70 AND sg.storecode = ‘Q1’ AND sg.termid = 2000 AND sg.course_number LIKE ‘271%’WHERE s.enroll_status = 0 AND s.schoolid = 100ORDER BY s.grade_level, s.lastfirst
![Page 26: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/26.jpg)
SQL Built-in Functions• Allow manipulation of returned fields
• Examples• To_char()
• To_char(entrydate,’YYYYMMDD’)
• Upper()/Lower()• Upper(last_name)
• Decode()• Decode(grade_level,-1,PK,0,K,grade_level)
• Many more• Oracle/PLSQL: Built-in Functions
![Page 27: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/27.jpg)
What are sqlReports?• Free customization for PowerSchool created by Dean Dahlvang
(PS user in Minnesota)
• Creates a new tab on the Reports page
• Harnesses SQL to search multiple tables and create user-runnable reports
• Allows importing and exporting for sharing among systems
![Page 28: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/28.jpg)
How do I get sqlReports?• Download Custom Reports Bundle from
powerdatasolutions.org
• Installation:• Copy the bundle into the custom web_root, or• Upload via CPM
• Ensure customization is turned on• System System Settings Customization
![Page 29: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/29.jpg)
Creating an sqlReport• Start Page System Reports Custom SQL Reports
![Page 30: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/30.jpg)
Creating an sqlReport (cont.)• Click the “Create a new sqlReport” link
![Page 31: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/31.jpg)
Report Information
![Page 32: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/32.jpg)
Report Information (cont.)
![Page 33: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/33.jpg)
Query Section
![Page 34: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/34.jpg)
SQL Queryselect
s.lastfirst, decode(s.schoolid,100,'MLGES',105,'SMMS',110,'SMES',
182,'CMS',187,'CRES',189,'MHES',192,'WES',193,'KES',195,'DLRES',197,'SES',295,'CCHS',495,'MLCES'), decode(s.enroll_status,-1,'Pre-Registered',0,'Active',2,'Transferred Out',3,'Graduated',4,'Imported as Historical')
from students s
where s.last_name like 'Smith%'
![Page 35: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/35.jpg)
Query Section (cont.)• Paste SQL query and click Build Header• Replace “Column X” with header names
![Page 36: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/36.jpg)
Student Selection
![Page 37: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/37.jpg)
Student Selection (cont.)• Check box and click Build Query• Insert DCID alias (if necessary) and remove Order By clause
![Page 38: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/38.jpg)
Parameters
![Page 39: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/39.jpg)
Parameters (cont.)• Replace comparison value with %paramX”, where X is the
parameter number
![Page 40: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/40.jpg)
Parameters (cont.)• Enter display name and default value
![Page 41: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/41.jpg)
Examples
![Page 42: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/42.jpg)
Export a template• Right click export link to save report template as a text file
![Page 43: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/43.jpg)
Template Contents
![Page 44: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/44.jpg)
Import Template
![Page 45: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/45.jpg)
Import Template (cont.)
![Page 46: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/46.jpg)
Template Contents• Remove
![Page 47: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/47.jpg)
Examples
![Page 48: An Intro to Writing SQL Queries & Using the sqlReports Customization for PowerSchool Chris A. McManigal Camden County Schools Kingsland, GA.](https://reader035.fdocuments.in/reader035/viewer/2022062314/56649d8d5503460f94a7646b/html5/thumbnails/48.jpg)
Q & A