Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My solution for sql lab #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions code_here.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"SELECT \n",
" a.au_id AS \"AUTHOR ID\",\n",
" a.au_lname AS \"LAST NAME\",\n",
" a.au_fname AS \"FIRST NAME\",\n",
" t.title AS \"TITLE\",\n",
" p.pub_name AS \"PUBLISHER\"\n",
"FROM authors a\n",
"JOIN titleauthor ta ON a.au_id = ta.au_id\n",
"JOIN titles t ON ta.title_id = t.title_id\n",
"JOIN publishers p ON t.pub_id = p.pub_id\n",
"ORDER BY a.au_id, t.title;\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 2 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"SELECT \n",
" a.au_id AS \"AUTHOR ID\",\n",
" a.au_lname AS \"LAST NAME\",\n",
" a.au_fname AS \"FIRST NAME\",\n",
" p.pub_name AS \"PUBLISHER\",\n",
" COUNT(t.title_id) AS \"TITLE COUNT\"\n",
"FROM authors a\n",
"JOIN titleauthor ta ON a.au_id = ta.au_id\n",
"JOIN titles t ON ta.title_id = t.title_id\n",
"JOIN publishers p ON t.pub_id = p.pub_id\n",
"GROUP BY a.au_id, a.au_lname, a.au_fname, p.pub_name\n",
"ORDER BY a.au_id, p.pub_name;\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"SELECT \n",
" a.au_id AS \"AUTHOR ID\",\n",
" a.au_lname AS \"LAST NAME\",\n",
" a.au_fname AS \"FIRST NAME\",\n",
" SUM(s.qty) AS \"TOTAL\"\n",
"FROM authors a\n",
"JOIN titleauthor ta ON a.au_id = ta.au_id\n",
"JOIN sales s ON ta.title_id = s.title_id\n",
"GROUP BY a.au_id, a.au_lname, a.au_fname\n",
"ORDER BY TOTAL DESC\n",
"LIMIT 3;\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"899-46-2035\tRinger\tAnne\t148\n",
"998-72-3567\tRinger\tAlbert\t133\n",
"213-46-8915\tGreen\tMarjorie\t50\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"SELECT \n",
" a.au_id AS \"AUTHOR ID\",\n",
" a.au_lname AS \"LAST NAME\",\n",
" a.au_fname AS \"FIRST NAME\",\n",
" COALESCE(SUM(s.qty), 0) AS \"TOTAL\"\n",
"FROM authors a\n",
"LEFT JOIN titleauthor ta ON a.au_id = ta.au_id\n",
"LEFT JOIN sales s ON ta.title_id = s.title_id\n",
"GROUP BY a.au_id, a.au_lname, a.au_fname\n",
"ORDER BY TOTAL DESC;\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"899-46-2035\tRinger\tAnne\t148\n",
"998-72-3567\tRinger\tAlbert\t133\n",
"213-46-8915\tGreen\tMarjorie\t50\n",
"427-17-2319\tDull\tAnn\t50\n",
"846-92-7186\tHunter\tSheryl\t50\n",
"267-41-2394\tO'Leary\tMichael\t45\n",
"724-80-9391\tMacFeather\tStearns\t45\n",
"722-51-5454\tDeFrance\tMichel\t40\n",
"807-91-6654\tPanteley\tSylvia\t40\n",
"238-95-7766\tCarson\tCheryl\t30\n",
"486-29-1786\tLocksley\tCharlene\t25\n",
"472-27-2349\tGringlesby\tBurt\t20\n",
"648-92-1872\tBlotchet-Halls\tReginald\t20\n",
"672-71-3249\tYokomoto\tAkiko\t20\n",
"756-30-7391\tKarsen\tLivia\t20\n",
"172-32-1176\tWhite\tJohnson\t15\n",
"274-80-9391\tStraight\tDean\t15\n",
"409-56-7008\tBennet\tAbraham\t15\n",
"712-45-1867\tdel Castillo\tInnes\t10\n",
"341-22-1782\tSmith\tMeander\t0\n",
"527-72-3246\tGreene\tMorningstar\t0\n",
"724-08-9931\tStringer\tDirk\t0\n",
"893-72-1158\tMcBadden\tHeather\t0\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}