runtime
23 / 139

task CREATE / ALTER · easy

Create a wishlist table

Create wishlist with customer_id INTEGER referencing customers(customer_id), stock_code TEXT referencing products(stock_code), added_at TEXT NOT NULL, and PRIMARY KEY (customer_id, stock_code). Insert (12347, '85123A', '2011-12-01') and (12347, '22423', '2011-12-02'). Return customer_id, stock_code and added_at.

what to return

Columns
customer_idstock_codeadded_at in this order
Rows
2 rows · any order
Skill
Define a table with keys that protect relationships. Refresher: DDL: create, alter & inspect a table →

expected result

expected result2 rows · any order
customer_idstock_codeadded_at
1234785123A2011-12-01
12347224232011-12-02

all 2 rows

data you can query

customers4 columns · 848 rows
customer_idnumber · unique idcountrytextregiontextfirst_order_atdate & time
12347IcelandEurope2010-10-31 14:20:00
12353BahrainRest of World2010-10-27 12:44:00
12359CyprusEurope2009-12-05 13:32:00
12373AustriaEurope2010-02-04 12:08:00
12374AustriaEurope2010-04-30 14:01:00
12384SwitzerlandEurope2011-08-10 11:23:00
12389AustraliaRest of World2010-02-22 10:15:00
12392AustraliaRest of World2010-04-27 14:04:00
12404FinlandEurope2010-01-26 16:25:00
12416AustraliaRest of World2010-02-21 10:19:00
customer_idnumber · unique id
12347
countrytext
Iceland
regiontext
Europe
first_order_atdate & time
2010-10-31 14:20:00
customer_idnumber · unique id
12353
countrytext
Bahrain
regiontext
Rest of World
first_order_atdate & time
2010-10-27 12:44:00
customer_idnumber · unique id
12359
countrytext
Cyprus
regiontext
Europe
first_order_atdate & time
2009-12-05 13:32:00
customer_idnumber · unique id
12373
countrytext
Austria
regiontext
Europe
first_order_atdate & time
2010-02-04 12:08:00
customer_idnumber · unique id
12374
countrytext
Austria
regiontext
Europe
first_order_atdate & time
2010-04-30 14:01:00
customer_idnumber · unique id
12384
countrytext
Switzerland
regiontext
Europe
first_order_atdate & time
2011-08-10 11:23:00
customer_idnumber · unique id
12389
countrytext
Australia
regiontext
Rest of World
first_order_atdate & time
2010-02-22 10:15:00
customer_idnumber · unique id
12392
countrytext
Australia
regiontext
Rest of World
first_order_atdate & time
2010-04-27 14:04:00
customer_idnumber · unique id
12404
countrytext
Finland
regiontext
Europe
first_order_atdate & time
2010-01-26 16:25:00
customer_idnumber · unique id
12416
countrytext
Australia
regiontext
Rest of World
first_order_atdate & time
2010-02-21 10:19:00

first 10 of 848 rows · your queries use all of them

products6 columns · 5,304 rows
stock_codetext · unique iddescriptiontextcategory_idnumber · links to categorieslist_pricedecimalfirst_sold_atdate & timeis_merchandisenumber
10002INFLATABLE POLITICAL GLOBE170.852009-12-01 09:08:001
10002RROBOT PENCIL SHARPNER85.172009-12-02 14:43:001
10080GROOVY CACTUS INFLATABLE170.392009-12-02 16:02:001
10109BENDY COLOUR PENCILS80.422009-12-03 12:31:001
10120DOGGY RUBBER170.212009-12-01 16:17:001
10123CHEARTS WRAPPING TAPE80.652009-12-01 14:28:001
10123GARMY CAMO WRAPPING TAPE80.652009-12-01 14:28:001
10124ASPOTS ON RED BOOKCOVER TAPE80.422010-02-11 18:13:001
10124CNULLNULLNULL2010-05-11 12:51:001
10124GARMY CAMO BOOKCOVER TAPE80.422010-05-13 16:49:001
stock_codetext · unique id
10002
descriptiontext
INFLATABLE POLITICAL GLOBE
category_idnumber · links to categories
17
list_pricedecimal
0.85
first_sold_atdate & time
2009-12-01 09:08:00
is_merchandisenumber
1
stock_codetext · unique id
10002R
descriptiontext
ROBOT PENCIL SHARPNER
category_idnumber · links to categories
8
list_pricedecimal
5.17
first_sold_atdate & time
2009-12-02 14:43:00
is_merchandisenumber
1
stock_codetext · unique id
10080
descriptiontext
GROOVY CACTUS INFLATABLE
category_idnumber · links to categories
17
list_pricedecimal
0.39
first_sold_atdate & time
2009-12-02 16:02:00
is_merchandisenumber
1
stock_codetext · unique id
10109
descriptiontext
BENDY COLOUR PENCILS
category_idnumber · links to categories
8
list_pricedecimal
0.42
first_sold_atdate & time
2009-12-03 12:31:00
is_merchandisenumber
1
stock_codetext · unique id
10120
descriptiontext
DOGGY RUBBER
category_idnumber · links to categories
17
list_pricedecimal
0.21
first_sold_atdate & time
2009-12-01 16:17:00
is_merchandisenumber
1
stock_codetext · unique id
10123C
descriptiontext
HEARTS WRAPPING TAPE
category_idnumber · links to categories
8
list_pricedecimal
0.65
first_sold_atdate & time
2009-12-01 14:28:00
is_merchandisenumber
1
stock_codetext · unique id
10123G
descriptiontext
ARMY CAMO WRAPPING TAPE
category_idnumber · links to categories
8
list_pricedecimal
0.65
first_sold_atdate & time
2009-12-01 14:28:00
is_merchandisenumber
1
stock_codetext · unique id
10124A
descriptiontext
SPOTS ON RED BOOKCOVER TAPE
category_idnumber · links to categories
8
list_pricedecimal
0.42
first_sold_atdate & time
2010-02-11 18:13:00
is_merchandisenumber
1
stock_codetext · unique id
10124C
descriptiontext
NULL
category_idnumber · links to categories
NULL
list_pricedecimal
NULL
first_sold_atdate & time
2010-05-11 12:51:00
is_merchandisenumber
1
stock_codetext · unique id
10124G
descriptiontext
ARMY CAMO BOOKCOVER TAPE
category_idnumber · links to categories
8
list_pricedecimal
0.42
first_sold_atdate & time
2010-05-13 16:49:00
is_merchandisenumber
1

first 10 of 5,304 rows · your queries use all of them

solution.sql
 
Output

Hints and the answer are always available. Using them counts the question as solved with help.

Create a wishlist table — SQL practice · Runtime