Skip to content

Azzam basic SQL #64

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

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
240 changes: 240 additions & 0 deletions solutions.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT client_id\n",
"FROM client\n",
"WHERE district_id = 1\n",
"LIMIT 5;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT client_id\n",
"FROM client\n",
"WHERE district_id = 72\n",
"ORDER BY client_id DESC\n",
"LIMIT 1;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT amount\n",
"FROM loan\n",
"ORDER BY amount ASC\n",
"LIMIT 3;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT DISTINCT status\n",
"FROM loan\n",
"ORDER BY status ASC;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT loan_id\n",
"FROM loan\n",
"ORDER BY payments DESC\n",
"LIMIT 1;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT account_id, amount\n",
"FROM loan\n",
"ORDER BY account_id ASC\n",
"LIMIT 5;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT account_id, amount\n",
"FROM loan\n",
"WHERE duration = 60\n",
"AND amount = (\n",
" SELECT MIN(amount)\n",
" FROM loan\n",
" WHERE duration = 60\n",
");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT DISTINCT k_symbol\n",
"FROM `order`\n",
"ORDER BY k_symbol ASC;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT order_id\n",
"FROM `order`\n",
"WHERE account_id = 34;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT account_id\n",
"FROM `order`\n",
"WHERE order_id BETWEEN 29540 AND 29560;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT amount\n",
"FROM `order`\n",
"WHERE account_to = 30067122;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT trans_id, date, type, amount\n",
"FROM `trans`\n",
"WHERE account_id = 793\n",
"ORDER BY date DESC\n",
"LIMIT 10;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT district_id, COUNT(*) AS client_count\n",
"FROM `client`\n",
"WHERE district_id < 10\n",
"GROUP BY district_id\n",
"ORDER BY district_id ASC;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT type, COUNT(*) AS card_count\n",
"FROM `card`\n",
"GROUP BY type\n",
"ORDER BY card_count DESC;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT account_id, SUM(amount) AS total_loan_amount\n",
"FROM `loan`\n",
"GROUP BY account_id\n",
"ORDER BY total_loan_amount DESC\n",
"LIMIT 10;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT date, COUNT(*) AS loan_count\n",
"FROM `loan`\n",
"WHERE date < 930907\n",
"GROUP BY date\n",
"ORDER BY date DESC;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT date, duration, COUNT(*) AS loan_count\n",
"FROM `loan`\n",
"WHERE date BETWEEN 19971201 AND 19971231\n",
"GROUP BY date, duration\n",
"ORDER BY date ASC, duration ASC;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SELECT account_id, type, SUM(amount) AS total_amount\n",
"FROM `trans`\n",
"WHERE account_id = 396\n",
"GROUP BY type\n",
"ORDER BY type ASC;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}