diff --git a/Teaching/JHU/DataMining-553.436/Getting Started with SQL using SciServer.CasJobs.ipynb b/Teaching/JHU/DataMining-553.436/Getting Started with SQL using SciServer.CasJobs.ipynb
deleted file mode 100644
index fb822bf..0000000
--- a/Teaching/JHU/DataMining-553.436/Getting Started with SQL using SciServer.CasJobs.ipynb
+++ /dev/null
@@ -1,3542 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Getting Started with SQL \n",
- "\n",
- "#### TAMÁS BUDAVÁRI – AUGUST 2016 \n",
- " \n",
- "Databases are easy: they consist of tables, which in turn have columns – just like the files with which you \n",
- "are probably used to working. The difference is that you don’t have to think about how to read and write \n",
- "the files but can focus on the questions you try to answer. The following code snippets and exercises will \n",
- "teach you the basics of expressing your questions in the Structure Query Language, or SQL for short. SQL \n",
- "is a standard language and most of these commands will work on any relational database but there are \n",
- "minor differences in dialects. \n",
- " \n",
- "The database you will be querying stores a collection of measurements of some (X,Y) quantities. There is \n",
- "a relation between them but the Y measurements are noisy. Our database is synthetic but carries several \n",
- "aspects of real measurements: separate instruments, multiple students and runs of measurements in \n",
- "different observational domains. The relevant tables are Data, Runs, Instruments and Users. The names \n",
- "should be suggestive of their contents.\n",
- "\n",
- "You have tried out some SQL queries using the online CasJobs web application. Here we use many of these same queries as examples for accessing a set of relational databases from within Jupyter notebooks running python inside a \n",
- "SciServer/Compute container.\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## SciServer.CasJobs\n",
- "From a python notebook in SciServer/Compute you can submit SQL queries to the same service that runs queries from the CasJobs webpage. The advantage is that you can directly access the result and visualize it or analyze it in any way you want.\n",
- "\n",
- "To do so you must import a library that is available on all the SciServer Compute images."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import SciServer.CasJobs as cj"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## The First Queries \n",
- "To get all (X,Y) values from the table Data, you could use the following SQL:"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "``` sql\n",
- "-- never run queries like this \n",
- "select X, Y \n",
- "from Data \n",
- "```"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "But don’t do it! First you should always think about what will happen. \n",
- "\n",
- "The table might have hundreds of millions of rows! Do you really want all that data dumped on you? Try \n",
- "the next set of commands to see their effects and understand how they work. Consider them as \n",
- "illustrations accompanying the lecture and ask questions if something is not clear! "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "sql=\"\"\"\n",
- "-- have a quick peek \n",
- "select top 5 X, Y \n",
- "from Data \n",
- "\"\"\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "To execute this query you will use the SciServer.CasJobs library, which we aliased to 'cj' in the import statement.\n",
- "Its 'executeQuery' function submits the specified sql to the specified context
\n",
- "As written here this query will be executed \"synchronously\" and return the result as a pandas DataFrame that will be printed at the end of the cell."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " X | \n",
- " Y | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.145097 | \n",
- " -1.131867 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.200108 | \n",
- " -0.337185 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 0.405262 | \n",
- " -0.246609 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 0.338955 | \n",
- " -1.156640 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 0.089844 | \n",
- " -1.062386 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " X Y\n",
- "0 0.145097 -1.131867\n",
- "1 0.200108 -0.337185\n",
- "2 0.405262 -0.246609\n",
- "3 0.338955 -1.156640\n",
- "4 0.089844 -1.062386"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df=cj.executeQuery(sql=sql,context=\"IntroSQL\")\n",
- "df"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "If you only want to inspect the result you do not need to store it in a variable. And note that you do not need to be explicit about the variables. See docs for documentation on all the SciServer python modules. In particular SciServer.CasJobs for the CasJobs module."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " X | \n",
- " Y | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.001319 | \n",
- " -1.121337 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.001944 | \n",
- " -0.888723 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 0.002475 | \n",
- " -0.770705 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " X Y\n",
- "0 0.001319 -1.121337\n",
- "1 0.001944 -0.888723\n",
- "2 0.002475 -0.770705"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# sorting to peek at the extremes \n",
- "sql=\"\"\"\n",
- "select top 3 X, Y \n",
- "from Data \n",
- "order by X \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " x | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.546278 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.434254 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 0.438969 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 0.501610 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 0.430480 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " x\n",
- "0 0.546278\n",
- "1 0.434254\n",
- "2 0.438969\n",
- "3 0.501610\n",
- "4 0.430480"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- filtering with formulas and functions \n",
- "select top 5 x \n",
- "from Data \n",
- "where 2*y between -sin(x) and x \n",
- "order by RunID desc, y desc \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "The last query showed you that you can comment your SQL code by using the following formats \n",
- " \n",
- "-- single-line comments go after -- \n",
- " \n",
- "/* multi-line comments are \n",
- " like this one \n",
- "*/ \n",
- "
\n",
- " "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# NOT TRUE:\n",
- "### SAVE YOUR WORK! \n",
- "The website you are using will not save your queries. If you would \n",
- "like to keep them for future reference, open a text editor to cut & \n",
- "paste the relevant lines into a file that you can regularly save. \n",
- " \n",
- "IF you save your notebook in a volume in your private /Storage/<username> area, for example /persistent, your notebook will be backed up and available in other containers as well.\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Aggregation\n",
- "Consider getting only the relevant information from the database and not everything. Run the following \n",
- "commands and see what the different constructs achieve: "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " N | \n",
- " Column1 | \n",
- " Column2 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 546 | \n",
- " 546 | \n",
- " 10 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " N Column1 Column2\n",
- "0 546 546 10"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- counting \n",
- "select COUNT(ID) as N, COUNT(RunID), COUNT(distinct RunID) \n",
- "from Data \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Column1 | \n",
- " Column2 | \n",
- " Column3 | \n",
- " Column4 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 230 | \n",
- " 127.140058 | \n",
- " 1.509137 | \n",
- " 1.403175 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Column1 Column2 Column3 Column4\n",
- "0 230 127.140058 1.509137 1.403175"
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- aggregates in general \n",
- "select COUNT(id), SUM(x), AVG(y), STDEV(x-y) \n",
- "from Data \n",
- "where Y>0 \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " RunID | \n",
- " Column1 | \n",
- " Column2 | \n",
- " Column3 | \n",
- " Column4 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 101 | \n",
- " 0.505333 | \n",
- " 0.994198 | \n",
- " -0.086970 | \n",
- " 2.975272 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 109 | \n",
- " 0.356064 | \n",
- " 0.879783 | \n",
- " -1.207412 | \n",
- " 1.644311 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 104 | \n",
- " 0.255726 | \n",
- " 0.789319 | \n",
- " -2.374107 | \n",
- " 1.774286 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 102 | \n",
- " 0.242926 | \n",
- " 0.773327 | \n",
- " -0.935795 | \n",
- " 1.074530 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 105 | \n",
- " 0.202550 | \n",
- " 0.797702 | \n",
- " -8.014773 | \n",
- " 6.073653 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 108 | \n",
- " 0.302871 | \n",
- " 0.599753 | \n",
- " -0.700361 | \n",
- " 0.266618 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 106 | \n",
- " 0.202057 | \n",
- " 0.799781 | \n",
- " -5.970850 | \n",
- " 4.230965 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 103 | \n",
- " 0.004561 | \n",
- " 0.881169 | \n",
- " -7.480040 | \n",
- " 5.935146 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 100 | \n",
- " 0.017204 | \n",
- " 0.492729 | \n",
- " -1.619121 | \n",
- " 0.487096 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 107 | \n",
- " 0.001319 | \n",
- " 0.097952 | \n",
- " -1.163017 | \n",
- " -0.693459 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " RunID Column1 Column2 Column3 Column4\n",
- "0 101 0.505333 0.994198 -0.086970 2.975272\n",
- "1 109 0.356064 0.879783 -1.207412 1.644311\n",
- "2 104 0.255726 0.789319 -2.374107 1.774286\n",
- "3 102 0.242926 0.773327 -0.935795 1.074530\n",
- "4 105 0.202550 0.797702 -8.014773 6.073653\n",
- "5 108 0.302871 0.599753 -0.700361 0.266618\n",
- "6 106 0.202057 0.799781 -5.970850 4.230965\n",
- "7 103 0.004561 0.881169 -7.480040 5.935146\n",
- "8 100 0.017204 0.492729 -1.619121 0.487096\n",
- "9 107 0.001319 0.097952 -1.163017 -0.693459"
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- grouping data \n",
- "select RunID, MIN(x), MAX(x), MIN(y), MAX(Y) \n",
- "from Data \n",
- "group by RunID \n",
- "order by AVG(X) desc \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " RunID | \n",
- " Column1 | \n",
- " Column2 | \n",
- " Column3 | \n",
- " Column4 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- "Empty DataFrame\n",
- "Columns: [RunID, Column1, Column2, Column3, Column4]\n",
- "Index: []"
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- having: contraints on aggregates \n",
- "select RunID, MIN(x), MAX(x), MIN(y), MAX(Y) \n",
- "from Data \n",
- "where X>0.2 -- filtering on the input \n",
- "group by RunID \n",
- "having MAX(Y) < 0 -- filtering on aggregate \n",
- "order by AVG(X) desc \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"AstroinformIntroSQLatics2018\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " RunID | \n",
- " Column1 | \n",
- " Column2 | \n",
- " Column3 | \n",
- " Column4 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 103 | \n",
- " 0.207009 | \n",
- " 0.881169 | \n",
- " -5.723222 | \n",
- " 5.935146 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 105 | \n",
- " 0.202550 | \n",
- " 0.797702 | \n",
- " -8.014773 | \n",
- " 6.073653 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 108 | \n",
- " 0.302871 | \n",
- " 0.599753 | \n",
- " -0.700361 | \n",
- " 0.266618 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 106 | \n",
- " 0.202057 | \n",
- " 0.799781 | \n",
- " -5.970850 | \n",
- " 4.230965 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " RunID Column1 Column2 Column3 Column4\n",
- "0 103 0.207009 0.881169 -5.723222 5.935146\n",
- "1 105 0.202550 0.797702 -8.014773 6.073653\n",
- "2 108 0.302871 0.599753 -0.700361 0.266618\n",
- "3 106 0.202057 0.799781 -5.970850 4.230965"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- or \n",
- "select RunID, MIN(x), MAX(x), MIN(y), MAX(Y) \n",
- "from Data \n",
- "where X>0.2 \n",
- "group by RunID \n",
- "having COUNT(*) > 30 \n",
- "order by AVG(X) desc \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 103 | \n",
- " 99 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 105 | \n",
- " 99 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 106 | \n",
- " 99 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 108 | \n",
- " 73 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 107 | \n",
- " 49 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 102 | \n",
- " 30 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 109 | \n",
- " 27 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 100 | \n",
- " 25 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 101 | \n",
- " 25 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 104 | \n",
- " 20 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " RunID Column1\n",
- "0 103 99\n",
- "1 105 99\n",
- "2 106 99\n",
- "3 108 73\n",
- "4 107 49\n",
- "5 102 30\n",
- "6 109 27\n",
- "7 100 25\n",
- "8 101 25\n",
- "9 104 20"
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- number of measurements in each run \n",
- "select RunID, COUNT(*) \n",
- "from Data \n",
- "group by RunID \n",
- "order by 2 desc \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " X | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.145097 | \n",
- " 0.02 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.200108 | \n",
- " 0.04 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 0.405262 | \n",
- " 0.16 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 0.338955 | \n",
- " 0.11 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 0.089844 | \n",
- " 0.01 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 0.131127 | \n",
- " 0.02 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 0.465117 | \n",
- " 0.22 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 0.049429 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 0.391001 | \n",
- " 0.15 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 0.357276 | \n",
- " 0.13 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 0.129908 | \n",
- " 0.02 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 0.348302 | \n",
- " 0.12 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 0.330393 | \n",
- " 0.11 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 0.178024 | \n",
- " 0.03 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 0.404610 | \n",
- " 0.16 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 0.061659 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 0.492729 | \n",
- " 0.24 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 0.017204 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 0.065357 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 0.355085 | \n",
- " 0.13 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 0.369850 | \n",
- " 0.14 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 0.364192 | \n",
- " 0.13 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 0.068344 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 0.396223 | \n",
- " 0.16 | \n",
- "
\n",
- " \n",
- " 24 | \n",
- " 0.104986 | \n",
- " 0.01 | \n",
- "
\n",
- " \n",
- " 25 | \n",
- " 0.981793 | \n",
- " 0.96 | \n",
- "
\n",
- " \n",
- " 26 | \n",
- " 0.613945 | \n",
- " 0.38 | \n",
- "
\n",
- " \n",
- " 27 | \n",
- " 0.662763 | \n",
- " 0.44 | \n",
- "
\n",
- " \n",
- " 28 | \n",
- " 0.767558 | \n",
- " 0.59 | \n",
- "
\n",
- " \n",
- " 29 | \n",
- " 0.994198 | \n",
- " 0.99 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 70 | \n",
- " 0.435793 | \n",
- " 0.19 | \n",
- "
\n",
- " \n",
- " 71 | \n",
- " 0.511613 | \n",
- " 0.26 | \n",
- "
\n",
- " \n",
- " 72 | \n",
- " 0.738097 | \n",
- " 0.54 | \n",
- "
\n",
- " \n",
- " 73 | \n",
- " 0.305846 | \n",
- " 0.09 | \n",
- "
\n",
- " \n",
- " 74 | \n",
- " 0.724111 | \n",
- " 0.52 | \n",
- "
\n",
- " \n",
- " 75 | \n",
- " 0.593763 | \n",
- " 0.35 | \n",
- "
\n",
- " \n",
- " 76 | \n",
- " 0.371776 | \n",
- " 0.14 | \n",
- "
\n",
- " \n",
- " 77 | \n",
- " 0.462956 | \n",
- " 0.21 | \n",
- "
\n",
- " \n",
- " 78 | \n",
- " 0.431236 | \n",
- " 0.19 | \n",
- "
\n",
- " \n",
- " 79 | \n",
- " 0.242926 | \n",
- " 0.06 | \n",
- "
\n",
- " \n",
- " 80 | \n",
- " 0.839875 | \n",
- " 0.71 | \n",
- "
\n",
- " \n",
- " 81 | \n",
- " 0.783815 | \n",
- " 0.61 | \n",
- "
\n",
- " \n",
- " 82 | \n",
- " 0.601005 | \n",
- " 0.36 | \n",
- "
\n",
- " \n",
- " 83 | \n",
- " 0.780251 | \n",
- " 0.61 | \n",
- "
\n",
- " \n",
- " 84 | \n",
- " 0.652454 | \n",
- " 0.43 | \n",
- "
\n",
- " \n",
- " 85 | \n",
- " 0.384627 | \n",
- " 0.15 | \n",
- "
\n",
- " \n",
- " 86 | \n",
- " 0.186540 | \n",
- " 0.03 | \n",
- "
\n",
- " \n",
- " 87 | \n",
- " 0.871552 | \n",
- " 0.76 | \n",
- "
\n",
- " \n",
- " 88 | \n",
- " 0.740827 | \n",
- " 0.55 | \n",
- "
\n",
- " \n",
- " 89 | \n",
- " 0.437515 | \n",
- " 0.19 | \n",
- "
\n",
- " \n",
- " 90 | \n",
- " 0.472008 | \n",
- " 0.22 | \n",
- "
\n",
- " \n",
- " 91 | \n",
- " 0.716693 | \n",
- " 0.51 | \n",
- "
\n",
- " \n",
- " 92 | \n",
- " 0.157553 | \n",
- " 0.02 | \n",
- "
\n",
- " \n",
- " 93 | \n",
- " 0.309754 | \n",
- " 0.10 | \n",
- "
\n",
- " \n",
- " 94 | \n",
- " 0.043183 | \n",
- " 0.00 | \n",
- "
\n",
- " \n",
- " 95 | \n",
- " 0.386268 | \n",
- " 0.15 | \n",
- "
\n",
- " \n",
- " 96 | \n",
- " 0.737191 | \n",
- " 0.54 | \n",
- "
\n",
- " \n",
- " 97 | \n",
- " 0.585478 | \n",
- " 0.34 | \n",
- "
\n",
- " \n",
- " 98 | \n",
- " 0.526038 | \n",
- " 0.28 | \n",
- "
\n",
- " \n",
- " 99 | \n",
- " 0.193036 | \n",
- " 0.04 | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 2 columns
\n",
- "
"
- ],
- "text/plain": [
- " X Column1\n",
- "0 0.145097 0.02\n",
- "1 0.200108 0.04\n",
- "2 0.405262 0.16\n",
- "3 0.338955 0.11\n",
- "4 0.089844 0.01\n",
- "5 0.131127 0.02\n",
- "6 0.465117 0.22\n",
- "7 0.049429 0.00\n",
- "8 0.391001 0.15\n",
- "9 0.357276 0.13\n",
- "10 0.129908 0.02\n",
- "11 0.348302 0.12\n",
- "12 0.330393 0.11\n",
- "13 0.178024 0.03\n",
- "14 0.404610 0.16\n",
- "15 0.061659 0.00\n",
- "16 0.492729 0.24\n",
- "17 0.017204 0.00\n",
- "18 0.065357 0.00\n",
- "19 0.355085 0.13\n",
- "20 0.369850 0.14\n",
- "21 0.364192 0.13\n",
- "22 0.068344 0.00\n",
- "23 0.396223 0.16\n",
- "24 0.104986 0.01\n",
- "25 0.981793 0.96\n",
- "26 0.613945 0.38\n",
- "27 0.662763 0.44\n",
- "28 0.767558 0.59\n",
- "29 0.994198 0.99\n",
- ".. ... ...\n",
- "70 0.435793 0.19\n",
- "71 0.511613 0.26\n",
- "72 0.738097 0.54\n",
- "73 0.305846 0.09\n",
- "74 0.724111 0.52\n",
- "75 0.593763 0.35\n",
- "76 0.371776 0.14\n",
- "77 0.462956 0.21\n",
- "78 0.431236 0.19\n",
- "79 0.242926 0.06\n",
- "80 0.839875 0.71\n",
- "81 0.783815 0.61\n",
- "82 0.601005 0.36\n",
- "83 0.780251 0.61\n",
- "84 0.652454 0.43\n",
- "85 0.384627 0.15\n",
- "86 0.186540 0.03\n",
- "87 0.871552 0.76\n",
- "88 0.740827 0.55\n",
- "89 0.437515 0.19\n",
- "90 0.472008 0.22\n",
- "91 0.716693 0.51\n",
- "92 0.157553 0.02\n",
- "93 0.309754 0.10\n",
- "94 0.043183 0.00\n",
- "95 0.386268 0.15\n",
- "96 0.737191 0.54\n",
- "97 0.585478 0.34\n",
- "98 0.526038 0.28\n",
- "99 0.193036 0.04\n",
- "\n",
- "[100 rows x 2 columns]"
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- rounding is easy \n",
- "select top 100 X, ROUND(X*X,2) from Data \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " X | \n",
- " N | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.00 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.01 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 0.02 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 0.03 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 0.04 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 0.05 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 0.06 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 0.07 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 0.08 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 0.09 | \n",
- " 11 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 0.10 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 0.11 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 0.12 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 0.13 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 0.15 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 0.16 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 0.17 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 0.18 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 0.19 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 0.20 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 0.21 | \n",
- " 12 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 0.22 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 0.23 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 0.24 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 24 | \n",
- " 0.25 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 25 | \n",
- " 0.26 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 26 | \n",
- " 0.27 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 27 | \n",
- " 0.28 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 28 | \n",
- " 0.29 | \n",
- " 7 | \n",
- "
\n",
- " \n",
- " 29 | \n",
- " 0.30 | \n",
- " 10 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 64 | \n",
- " 0.65 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 65 | \n",
- " 0.66 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 66 | \n",
- " 0.67 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 67 | \n",
- " 0.68 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 68 | \n",
- " 0.69 | \n",
- " 7 | \n",
- "
\n",
- " \n",
- " 69 | \n",
- " 0.70 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 70 | \n",
- " 0.71 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 71 | \n",
- " 0.72 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 72 | \n",
- " 0.73 | \n",
- " 6 | \n",
- "
\n",
- " \n",
- " 73 | \n",
- " 0.74 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 74 | \n",
- " 0.75 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 75 | \n",
- " 0.76 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 76 | \n",
- " 0.77 | \n",
- " 11 | \n",
- "
\n",
- " \n",
- " 77 | \n",
- " 0.78 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 78 | \n",
- " 0.79 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 79 | \n",
- " 0.80 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 80 | \n",
- " 0.81 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 81 | \n",
- " 0.83 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 82 | \n",
- " 0.84 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 83 | \n",
- " 0.85 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 84 | \n",
- " 0.86 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 85 | \n",
- " 0.87 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 86 | \n",
- " 0.88 | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 87 | \n",
- " 0.90 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 88 | \n",
- " 0.91 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 89 | \n",
- " 0.92 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 90 | \n",
- " 0.93 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 91 | \n",
- " 0.97 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 92 | \n",
- " 0.98 | \n",
- " 2 | \n",
- "
\n",
- " \n",
- " 93 | \n",
- " 0.99 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- "
\n",
- "
94 rows × 2 columns
\n",
- "
"
- ],
- "text/plain": [
- " X N\n",
- "0 0.00 4\n",
- "1 0.01 8\n",
- "2 0.02 6\n",
- "3 0.03 6\n",
- "4 0.04 6\n",
- "5 0.05 8\n",
- "6 0.06 8\n",
- "7 0.07 5\n",
- "8 0.08 5\n",
- "9 0.09 11\n",
- "10 0.10 5\n",
- "11 0.11 3\n",
- "12 0.12 1\n",
- "13 0.13 2\n",
- "14 0.15 2\n",
- "15 0.16 1\n",
- "16 0.17 1\n",
- "17 0.18 1\n",
- "18 0.19 3\n",
- "19 0.20 4\n",
- "20 0.21 12\n",
- "21 0.22 4\n",
- "22 0.23 3\n",
- "23 0.24 5\n",
- "24 0.25 3\n",
- "25 0.26 5\n",
- "26 0.27 5\n",
- "27 0.28 8\n",
- "28 0.29 7\n",
- "29 0.30 10\n",
- ".. ... ..\n",
- "64 0.65 6\n",
- "65 0.66 8\n",
- "66 0.67 2\n",
- "67 0.68 6\n",
- "68 0.69 7\n",
- "69 0.70 6\n",
- "70 0.71 5\n",
- "71 0.72 8\n",
- "72 0.73 6\n",
- "73 0.74 4\n",
- "74 0.75 4\n",
- "75 0.76 3\n",
- "76 0.77 11\n",
- "77 0.78 5\n",
- "78 0.79 4\n",
- "79 0.80 5\n",
- "80 0.81 1\n",
- "81 0.83 2\n",
- "82 0.84 2\n",
- "83 0.85 1\n",
- "84 0.86 5\n",
- "85 0.87 3\n",
- "86 0.88 3\n",
- "87 0.90 1\n",
- "88 0.91 1\n",
- "89 0.92 1\n",
- "90 0.93 1\n",
- "91 0.97 1\n",
- "92 0.98 2\n",
- "93 0.99 1\n",
- "\n",
- "[94 rows x 2 columns]"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- building a histogram \n",
- "select ROUND(x,2) as X, COUNT(*) as N \n",
- "from Data \n",
- "group by ROUND(x,2) \n",
- "order by 1 \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can use the same SELECT ... INTO ...
pattern to save results in your MyDB. Make sure though that a table with this name does not already exist!"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 34,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Rows Affected | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 61 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Rows Affected\n",
- "0 61"
- ]
- },
- "execution_count": 34,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- custom bin size using a variable and save the results \n",
- "declare @bin float = 0.016 \n",
- "select ROUND(x/@bin,0)*@bin as X, COUNT(*) as Cts \n",
- "into AHistogram -- name of new table \n",
- "from Data \n",
- "group by ROUND(x/@bin,0)*@bin \n",
- "order by ROUND(x/@bin,0)*@bin \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Check that the table was indeed created in your MyDB in the CasJobs UI at https://skyserver.sdss.org/CasJobs/MyDB.aspx"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Asking Questions using SQL \n",
- "\n",
- "You’ll see that every question you have about the data will nicely translate to commands. For example, \n",
- "let’s consider the following question: Who ran the first measurement? The following 3 select statements \n",
- "will get you an answer. Note, you can run all three queries using a single execution. When more than 1 result is returned from the database, the result is a list of data frames: "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {},
- "outputs": [],
- "source": [
- "sql=\"\"\"\n",
- "select top 1 RunID from Data order by ID -- 100 \n",
- "select UserID from Runs where RunID=100 -- 12 \n",
- "select * from Users where UserID=12 \n",
- "\"\"\"\n",
- "dfs=cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Loop over the elements in the result, each of which is a DataFrame:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 33,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "0 :\n",
- " RunID\n",
- "0 100\n",
- "1 :\n",
- " UserID\n",
- "0 12\n",
- "2 :\n",
- " UserID Name AdvisorID\n",
- "0 12 Hugo First 10\n"
- ]
- }
- ],
- "source": [
- "for idx, df in enumerate(dfs):\n",
- " print(idx,\":\")\n",
- " print(df)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "What did we really mean by “first” measurement? Any other definition to use? \n",
- " \n",
- "Nested queries can combine multiple searches into one request. Run and analyze the following queries \n",
- "and their results: "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 35,
- "metadata": {},
- "outputs": [],
- "source": [
- "sql=\"\"\"\n",
- "-- nested queries \n",
- "select UserID \n",
- "from Runs \n",
- "where RunID = (select top 1 RunID from Data order by ID) \n",
- " \n",
- "-- doubly so \n",
- "select * from Users \n",
- "where UserID = ( \n",
- " select UserID from Runs \n",
- " where RunID = (select top 1 RunID from Data order by ID) \n",
- ") \n",
- " \n",
- "-- whole set of runs using the 'in' keyword \n",
- "select UserID \n",
- "from Runs \n",
- "where RunID in (select top 1 RunID \n",
- " from Data order by ID) \n",
- "\"\"\"\n",
- "dfs=cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 36,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "0 :\n",
- " UserID\n",
- "0 12\n",
- "1 :\n",
- " UserID Name AdvisorID\n",
- "0 12 Hugo First 10\n",
- "2 :\n",
- " UserID\n",
- "0 12\n"
- ]
- }
- ],
- "source": [
- "for idx, df in enumerate(dfs):\n",
- " print(idx,\":\")\n",
- " print(df)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Combining tables is where relational database engines really shine. The terminology is “joining tables”. \n",
- "Here are different implementations of similar questions. Make sure you understand these queries \n",
- "because they will be important: \n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 37,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Hugo First | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Hugo First | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Hammond Eggs | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Gil T. Azell | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Holly Wood | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " Gil T. Azell | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " Gil T. Azell | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " Holly Wood | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " Holly Wood | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " Levy Tate | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Name RunID Column1\n",
- "0 Hugo First 100 0.5\n",
- "1 Hugo First 101 0.5\n",
- "2 Hammond Eggs 102 0.6\n",
- "3 Gil T. Azell 103 0.9\n",
- "4 Holly Wood 104 0.6\n",
- "5 Gil T. Azell 105 0.6\n",
- "6 Gil T. Azell 106 0.6\n",
- "7 Holly Wood 107 0.1\n",
- "8 Holly Wood 108 0.3\n",
- "9 Levy Tate 109 0.6"
- ]
- },
- "execution_count": 37,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- inner join (old style) \n",
- "select u.Name, r.RunID, r.Xmax - r.Xmin \n",
- "from Runs r, Users u -- aliases are convenient \n",
- "where r.UserID=u.UserID \n",
- "-- risk of forgetting a constraint when many tables \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 38,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Hugo First | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Hugo First | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Hammond Eggs | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Gil T. Azell | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Holly Wood | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " Gil T. Azell | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " Gil T. Azell | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " Holly Wood | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " Holly Wood | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " Levy Tate | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Name RunID Column1\n",
- "0 Hugo First 100 0.5\n",
- "1 Hugo First 101 0.5\n",
- "2 Hammond Eggs 102 0.6\n",
- "3 Gil T. Azell 103 0.9\n",
- "4 Holly Wood 104 0.6\n",
- "5 Gil T. Azell 105 0.6\n",
- "6 Gil T. Azell 106 0.6\n",
- "7 Holly Wood 107 0.1\n",
- "8 Holly Wood 108 0.3\n",
- "9 Levy Tate 109 0.6"
- ]
- },
- "execution_count": 38,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- inner join (preferred) \n",
- "select u.Name, r.RunID, r.Xmax - r.Xmin \n",
- "from Runs r \n",
- " join Users u on u.UserID=r.UserID \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 39,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Hugo First | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Hugo First | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Hammond Eggs | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Gil T. Azell | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Holly Wood | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " Gil T. Azell | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " Gil T. Azell | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " Holly Wood | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " Holly Wood | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " Levy Tate | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Name RunID Column1\n",
- "0 Hugo First 100 0.5\n",
- "1 Hugo First 101 0.5\n",
- "2 Hammond Eggs 102 0.6\n",
- "3 Gil T. Azell 103 0.9\n",
- "4 Holly Wood 104 0.6\n",
- "5 Gil T. Azell 105 0.6\n",
- "6 Gil T. Azell 106 0.6\n",
- "7 Holly Wood 107 0.1\n",
- "8 Holly Wood 108 0.3\n",
- "9 Levy Tate 109 0.6"
- ]
- },
- "execution_count": 39,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"-- or explicitly \n",
- "select u.Name, r.RunID, r.Xmax - r.Xmin \n",
- "from Runs r \n",
- " inner join Users u on u.UserID=r.UserID \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 40,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Gil T. Azell | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Hammond Eggs | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Holly Wood | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Hugo First | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Levy Tate | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Name\n",
- "0 Gil T. Azell\n",
- "1 Hammond Eggs\n",
- "2 Holly Wood\n",
- "3 Hugo First\n",
- "4 Levy Tate"
- ]
- },
- "execution_count": 40,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\" \n",
- "-- list of users with measurements \n",
- "select distinct u.Name \n",
- "from Runs r \n",
- " join Users u on u.UserID=r.UserID \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "A different kind of join is used less frequently to look at all combinations of rows in the specified tables. \n",
- "Compare the following queries to the previous ones and run them to see the differences in the results: \n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 42,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Andy Structible | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Andy Structible | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Andy Structible | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Andy Structible | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Andy Structible | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " Andy Structible | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " Andy Structible | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " Andy Structible | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " Andy Structible | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " Andy Structible | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " Jack Pot | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " Jack Pot | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " Jack Pot | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " Jack Pot | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " Jack Pot | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " Jack Pot | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " Jack Pot | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " Jack Pot | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " Jack Pot | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " Jack Pot | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " Hugo First | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " Hugo First | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " Hugo First | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " Hugo First | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 24 | \n",
- " Hugo First | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 25 | \n",
- " Hugo First | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 26 | \n",
- " Hugo First | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 27 | \n",
- " Hugo First | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 28 | \n",
- " Hugo First | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 29 | \n",
- " Hugo First | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 40 | \n",
- " Gil T. Azell | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 41 | \n",
- " Gil T. Azell | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 42 | \n",
- " Gil T. Azell | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 43 | \n",
- " Gil T. Azell | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 44 | \n",
- " Gil T. Azell | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 45 | \n",
- " Gil T. Azell | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 46 | \n",
- " Gil T. Azell | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 47 | \n",
- " Gil T. Azell | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 48 | \n",
- " Gil T. Azell | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 49 | \n",
- " Gil T. Azell | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 50 | \n",
- " Holly Wood | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 51 | \n",
- " Holly Wood | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 52 | \n",
- " Holly Wood | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 53 | \n",
- " Holly Wood | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 54 | \n",
- " Holly Wood | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 55 | \n",
- " Holly Wood | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 56 | \n",
- " Holly Wood | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 57 | \n",
- " Holly Wood | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 58 | \n",
- " Holly Wood | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 59 | \n",
- " Holly Wood | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 60 | \n",
- " Levy Tate | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 61 | \n",
- " Levy Tate | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 62 | \n",
- " Levy Tate | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 63 | \n",
- " Levy Tate | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 64 | \n",
- " Levy Tate | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 65 | \n",
- " Levy Tate | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 66 | \n",
- " Levy Tate | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 67 | \n",
- " Levy Tate | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 68 | \n",
- " Levy Tate | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 69 | \n",
- " Levy Tate | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- "
\n",
- "
70 rows × 3 columns
\n",
- "
"
- ],
- "text/plain": [
- " Name RunID Column1\n",
- "0 Andy Structible 100 0.5\n",
- "1 Andy Structible 101 0.5\n",
- "2 Andy Structible 102 0.6\n",
- "3 Andy Structible 103 0.9\n",
- "4 Andy Structible 104 0.6\n",
- "5 Andy Structible 105 0.6\n",
- "6 Andy Structible 106 0.6\n",
- "7 Andy Structible 107 0.1\n",
- "8 Andy Structible 108 0.3\n",
- "9 Andy Structible 109 0.6\n",
- "10 Jack Pot 100 0.5\n",
- "11 Jack Pot 101 0.5\n",
- "12 Jack Pot 102 0.6\n",
- "13 Jack Pot 103 0.9\n",
- "14 Jack Pot 104 0.6\n",
- "15 Jack Pot 105 0.6\n",
- "16 Jack Pot 106 0.6\n",
- "17 Jack Pot 107 0.1\n",
- "18 Jack Pot 108 0.3\n",
- "19 Jack Pot 109 0.6\n",
- "20 Hugo First 100 0.5\n",
- "21 Hugo First 101 0.5\n",
- "22 Hugo First 102 0.6\n",
- "23 Hugo First 103 0.9\n",
- "24 Hugo First 104 0.6\n",
- "25 Hugo First 105 0.6\n",
- "26 Hugo First 106 0.6\n",
- "27 Hugo First 107 0.1\n",
- "28 Hugo First 108 0.3\n",
- "29 Hugo First 109 0.6\n",
- ".. ... ... ...\n",
- "40 Gil T. Azell 100 0.5\n",
- "41 Gil T. Azell 101 0.5\n",
- "42 Gil T. Azell 102 0.6\n",
- "43 Gil T. Azell 103 0.9\n",
- "44 Gil T. Azell 104 0.6\n",
- "45 Gil T. Azell 105 0.6\n",
- "46 Gil T. Azell 106 0.6\n",
- "47 Gil T. Azell 107 0.1\n",
- "48 Gil T. Azell 108 0.3\n",
- "49 Gil T. Azell 109 0.6\n",
- "50 Holly Wood 100 0.5\n",
- "51 Holly Wood 101 0.5\n",
- "52 Holly Wood 102 0.6\n",
- "53 Holly Wood 103 0.9\n",
- "54 Holly Wood 104 0.6\n",
- "55 Holly Wood 105 0.6\n",
- "56 Holly Wood 106 0.6\n",
- "57 Holly Wood 107 0.1\n",
- "58 Holly Wood 108 0.3\n",
- "59 Holly Wood 109 0.6\n",
- "60 Levy Tate 100 0.5\n",
- "61 Levy Tate 101 0.5\n",
- "62 Levy Tate 102 0.6\n",
- "63 Levy Tate 103 0.9\n",
- "64 Levy Tate 104 0.6\n",
- "65 Levy Tate 105 0.6\n",
- "66 Levy Tate 106 0.6\n",
- "67 Levy Tate 107 0.1\n",
- "68 Levy Tate 108 0.3\n",
- "69 Levy Tate 109 0.6\n",
- "\n",
- "[70 rows x 3 columns]"
- ]
- },
- "execution_count": 42,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "-- cross join (old style) \n",
- "select u.Name, r.RunID, r.Xmax - r.Xmin \n",
- "from Runs r, Users u \n",
- "-- same as old-style inner join w/o contraint \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 43,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Name | \n",
- " RunID | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " Andy Structible | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " Andy Structible | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " Andy Structible | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " Andy Structible | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " Andy Structible | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " Andy Structible | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " Andy Structible | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " Andy Structible | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " Andy Structible | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " Andy Structible | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " Jack Pot | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " Jack Pot | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " Jack Pot | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " Jack Pot | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " Jack Pot | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " Jack Pot | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " Jack Pot | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " Jack Pot | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " Jack Pot | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " Jack Pot | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " Hugo First | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " Hugo First | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " Hugo First | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " Hugo First | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 24 | \n",
- " Hugo First | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 25 | \n",
- " Hugo First | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 26 | \n",
- " Hugo First | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 27 | \n",
- " Hugo First | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 28 | \n",
- " Hugo First | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 29 | \n",
- " Hugo First | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 40 | \n",
- " Gil T. Azell | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 41 | \n",
- " Gil T. Azell | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 42 | \n",
- " Gil T. Azell | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 43 | \n",
- " Gil T. Azell | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 44 | \n",
- " Gil T. Azell | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 45 | \n",
- " Gil T. Azell | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 46 | \n",
- " Gil T. Azell | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 47 | \n",
- " Gil T. Azell | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 48 | \n",
- " Gil T. Azell | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 49 | \n",
- " Gil T. Azell | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 50 | \n",
- " Holly Wood | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 51 | \n",
- " Holly Wood | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 52 | \n",
- " Holly Wood | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 53 | \n",
- " Holly Wood | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 54 | \n",
- " Holly Wood | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 55 | \n",
- " Holly Wood | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 56 | \n",
- " Holly Wood | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 57 | \n",
- " Holly Wood | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 58 | \n",
- " Holly Wood | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 59 | \n",
- " Holly Wood | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 60 | \n",
- " Levy Tate | \n",
- " 100 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 61 | \n",
- " Levy Tate | \n",
- " 101 | \n",
- " 0.5 | \n",
- "
\n",
- " \n",
- " 62 | \n",
- " Levy Tate | \n",
- " 102 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 63 | \n",
- " Levy Tate | \n",
- " 103 | \n",
- " 0.9 | \n",
- "
\n",
- " \n",
- " 64 | \n",
- " Levy Tate | \n",
- " 104 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 65 | \n",
- " Levy Tate | \n",
- " 105 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 66 | \n",
- " Levy Tate | \n",
- " 106 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- " 67 | \n",
- " Levy Tate | \n",
- " 107 | \n",
- " 0.1 | \n",
- "
\n",
- " \n",
- " 68 | \n",
- " Levy Tate | \n",
- " 108 | \n",
- " 0.3 | \n",
- "
\n",
- " \n",
- " 69 | \n",
- " Levy Tate | \n",
- " 109 | \n",
- " 0.6 | \n",
- "
\n",
- " \n",
- "
\n",
- "
70 rows × 3 columns
\n",
- "
"
- ],
- "text/plain": [
- " Name RunID Column1\n",
- "0 Andy Structible 100 0.5\n",
- "1 Andy Structible 101 0.5\n",
- "2 Andy Structible 102 0.6\n",
- "3 Andy Structible 103 0.9\n",
- "4 Andy Structible 104 0.6\n",
- "5 Andy Structible 105 0.6\n",
- "6 Andy Structible 106 0.6\n",
- "7 Andy Structible 107 0.1\n",
- "8 Andy Structible 108 0.3\n",
- "9 Andy Structible 109 0.6\n",
- "10 Jack Pot 100 0.5\n",
- "11 Jack Pot 101 0.5\n",
- "12 Jack Pot 102 0.6\n",
- "13 Jack Pot 103 0.9\n",
- "14 Jack Pot 104 0.6\n",
- "15 Jack Pot 105 0.6\n",
- "16 Jack Pot 106 0.6\n",
- "17 Jack Pot 107 0.1\n",
- "18 Jack Pot 108 0.3\n",
- "19 Jack Pot 109 0.6\n",
- "20 Hugo First 100 0.5\n",
- "21 Hugo First 101 0.5\n",
- "22 Hugo First 102 0.6\n",
- "23 Hugo First 103 0.9\n",
- "24 Hugo First 104 0.6\n",
- "25 Hugo First 105 0.6\n",
- "26 Hugo First 106 0.6\n",
- "27 Hugo First 107 0.1\n",
- "28 Hugo First 108 0.3\n",
- "29 Hugo First 109 0.6\n",
- ".. ... ... ...\n",
- "40 Gil T. Azell 100 0.5\n",
- "41 Gil T. Azell 101 0.5\n",
- "42 Gil T. Azell 102 0.6\n",
- "43 Gil T. Azell 103 0.9\n",
- "44 Gil T. Azell 104 0.6\n",
- "45 Gil T. Azell 105 0.6\n",
- "46 Gil T. Azell 106 0.6\n",
- "47 Gil T. Azell 107 0.1\n",
- "48 Gil T. Azell 108 0.3\n",
- "49 Gil T. Azell 109 0.6\n",
- "50 Holly Wood 100 0.5\n",
- "51 Holly Wood 101 0.5\n",
- "52 Holly Wood 102 0.6\n",
- "53 Holly Wood 103 0.9\n",
- "54 Holly Wood 104 0.6\n",
- "55 Holly Wood 105 0.6\n",
- "56 Holly Wood 106 0.6\n",
- "57 Holly Wood 107 0.1\n",
- "58 Holly Wood 108 0.3\n",
- "59 Holly Wood 109 0.6\n",
- "60 Levy Tate 100 0.5\n",
- "61 Levy Tate 101 0.5\n",
- "62 Levy Tate 102 0.6\n",
- "63 Levy Tate 103 0.9\n",
- "64 Levy Tate 104 0.6\n",
- "65 Levy Tate 105 0.6\n",
- "66 Levy Tate 106 0.6\n",
- "67 Levy Tate 107 0.1\n",
- "68 Levy Tate 108 0.3\n",
- "69 Levy Tate 109 0.6\n",
- "\n",
- "[70 rows x 3 columns]"
- ]
- },
- "execution_count": 43,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\" \n",
- "-- cross join: explicitly \n",
- "select u.Name, r.RunID, r.Xmax - r.Xmin \n",
- "from Runs r cross join Users u \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 44,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 7 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Column1\n",
- "0 7"
- ]
- },
- "execution_count": 44,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\" \n",
- "-- compare the size of the result set with these \n",
- "select COUNT(*) from users \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 41,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Column1 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 10 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Column1\n",
- "0 10"
- ]
- },
- "execution_count": 41,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "sql=\"\"\"\n",
- "select COUNT(*) from runs \n",
- "-- all combinations \n",
- "\"\"\"\n",
- "cj.executeQuery(sql,\"IntroSQL\")"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3.8 (py38)",
- "language": "python",
- "name": "py38"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.8.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}
diff --git a/Teaching/class20181128.ipynb b/Teaching/JHU/DataMining-553.436/class20181128.ipynb
similarity index 100%
rename from Teaching/class20181128.ipynb
rename to Teaching/JHU/DataMining-553.436/class20181128.ipynb