# Arch
sudo pacman -S --needed sqlite3
# Debian
sudo apt install sqlite3sqlite3 has been preinstalled.
Download sqlite-tools-win in https://www.sqlite.org/download.html, and then add environment variables to the system.
We use the dataset in TPC-H in this experiment: the csv files under data/. This repo includes the specification of TPC-H: tpc-h_v3.0.0.pdf. Page 13 includes the schema of each table.
We have provided the SQL statements to create tables: schema.sql. You may create tables on Linux and Mac in this way:
sqlite3 test.db < schema.sqlThen you should import the dataset into the database. The statements should be saved in load.sql.
Save the SQL statements of the following queries in <number>.sql, such as 1.sql, 2.sql, etc. For some queries, we list the tables needed by the query in the brackets at the beginning of the query description.
Please note the order of the queries. An earlier query may affect a later query.
- (
ORDERS) Get the sum ofO_TOTALPRICEof each customer with >20 orders. Each result row should includeO_CUSTKEY, the sum ofO_TOTALPRICE, and the number of orders. - (
LINEITEM) Increase the tax on items with a discount >0.02 by 10%. - (
LINEITEM) For each order, get the average discount of items with taxes <0.05. The results should be ordered by the average discount from largest to smallest. Only show the top 10 orders. Each result row should includeL_ORDERKEYand the average discount. - (
LINEITEM) Get the items with the largest discount. Each result row should includeL_ORDERKEYandL_LINENUMBER. - (
PARTSUPP) Get the sum ofPS_AVAILQTYof eachPS_PARTKEY. Each result row should includePS_PARTKEYand the sum ofPS_AVAILQTY.
-
(
CUSTOMER,ORDERS,NATION) Get the total price of all orders whose customers are fromCHINA. -
(
CUSTOMER,ORDERS) Find all customers with at least one order whose total price <10000. Each result row should include all columns inCUSTOMER. -
Find suppliers with >100 unique customers. Each result row should include the name of the supplier and the number of unique customers. The results should be firstly ordered by the number of unique customers from largest to smallest then ordered by the name of the supplier in descending order.
make testYou may also test problems one by one:
python3 test.py load
python3 test.py 1
python3 test.py 2
python3 test.py 3
...make submitThen submit submission.zip to autolab.
For Windows users:
- The autograder runs on Linux whose path separator is
/. Therefore, Windows users should replace the path separator\inload.sqlwith/before submitting. zipcommand is not available on Windows by default. Therefore, Windows users need to pack.sqlfiles intosubmission.zipmanually.
If you have any questions, you may ask them in the WeChat group or Web Learning (aka 网络学堂).
https://www.runoob.com/sqlite/sqlite-tutorial.html
How to import a csv file whose columns are separated by semicolons