Week 2

:: Query 1a ::

Query:
SELECT Wine_ID, Wine_name
FROM Wine
WHERE Wine_name LIKE 'J*';

Analysis: I would like to see a list of Wine IDs and wine names from the wine table of wines starting with the letter "J".

Wine_ID Wine_name
6 Justin Cal Ital
7 Justin Malbec
8 Justin Obtuse
9 Justin Cabernet Sauvignon
11 Justin Zinfandel
13 Justin Petit Verdot
14 Justin Isosceles

 


:: Query 1b ::

Query:
SELECT Wine.Wine_ID, Wine.Wine_name
FROM Wine
WHERE (((Wine.Wine_name) Not Like 'J*'));

Analysis: I would like to see a list of Wine IDs and wine names from the wine table of wines not starting with the letter "J".

Wine_ID Wine_name
1 The Holy Trinity Barossa
2 Umbria Vitiano
3 Châteauneuf-du-Pape La Bernardine
4 Stonestreet Chardonnay
5 Korbel Rouge
10 Korbel Moscato Frizzante
12 E. Guigal Châteauneuf-du-Pape

 


:: Query 2a ::

Query:
SELECT Wine_ID, Wine_name, Wine_amt
FROM Wine
WHERE Wine_amt In (33,40,18);

Analysis: I would like to see Wine IDs, Wine_names and Wine amounts from the Wine table with an amount of $33, $40 or $18.

Wine_ID Wine_name Wine_amt
1 The Holy Trinity Barossa $33.00
3 Châteauneuf-du-Pape La Bernardine $40.00
8 Justin Obtuse $18.00
9 Justin Cabernet Sauvignon $18.00

 


:: Query 2b ::

Query:
SELECT Wine_ID, Wine_name, Wine_amt
FROM Wine
WHERE Wine_amt NOT IN (33,40,18);

Analysis: I would like to see Wine IDs, Wine_names and Wine amounts from the Wine table with an amount other than $33, $40 or $18.

Wine_ID Wine_name Wine_amt
2 Umbria Vitiano $10.00
4 Stonestreet Chardonnay $23.75
5 Korbel Rouge $11.99
6 Justin Cal Ital $22.50
7 Justin Malbec $24.00
10 Korbel Moscato Frizzante $13.99
11 Justin Petit Verdot $24.00
12 E. Guigal Châteauneuf-du-Pape $29.00
13 Justin Zinfandel $32.00
14 Justin Isosceles $44.00

 


:: Query 3 ::

Query:
SELECT *
FROM Wine
WHERE Issue_date Between #11/1/2002# And #12/31/2002#;

Analysis: I would like to see every row and column from the Wine table with an issue date between Nov. 1, 2002 and Dec. 31, 2002.

Wine_ID Vintage_yr Wine_name Wine_qty Left_qty Volume Wine_amt Harvest_date Issue_date Buy_date BegDrink_yr EndDrink_yr
1 1999 The Holy Trinity Barossa 1 1 750 ml $33.00   12/15/2002 9/1/2003 2003 2008
3 2000 Châteauneuf-du-Pape La Bernardine 1 1 750 ml $40.00   11/30/2002 10/1/2003 2005 2010
5 Non-vintage Korbel Rouge 2 2 750 ml $11.99   12/15/2002 10/25/2003 2004 2004

 


:: Query 4a ::

Query:
SELECT *
FROM Wine
WHERE BegDrink_yr=2003 AND Left_qty>0;

Analysis: I would like to see every row and column from the Wine table with a BegDrink_yr of 2003 and Left_qty of more than 0.

Wine_ID Vintage_yr Wine_name Wine_qty Left_qty Volume Wine_amt Harvest_date Issue_date Buy_date BegDrink_yr EndDrink_yr
1 1999 The Holy Trinity Barossa 1 1 750 ml $33.00   12/15/2002 9/1/2003 2003 2008
2 2001 Umbria Vitiano 1 1 750 ml $10.00   5/31/2003 2/15/2003 2003 2003
12 2001 E. Guigal Châteauneuf-du-Pape 4 4 750 ml $29.00   8/31/2003 9/3/2003 2003 2008

 


:: Query 4b ::

Query:
SELECT *
FROM Wine
WHERE Issue_date In (#5/28/2001#,#12/15/2002#,#11/30/2002#);

Analysis: I would like to see every row and column from the Wine table with an Issue_date of 5/28/2001, 12/15/2002, 11/30/2002.

Wine_ID Vintage_yr Wine_name Wine_qty Left_qty Volume Wine_amt Harvest_date Issue_date Buy_date BegDrink_yr EndDrink_yr
1 1999 The Holy Trinity Barossa 1 1 750 ml $33.00   12/15/2002 9/1/2003 2003 2008
3 2000 Châteauneuf-du-Pape La Bernardine 1 1 750 ml $40.00   11/30/2002 10/1/2003 2005 2010
5 Non-vintage Korbel Rouge 2 2 750 ml $11.99   12/15/2002 10/25/2003 2004 2004
6 2000 Justin Cal Ital 1 1 750 ml $22.50   5/28/2001 6/1/2002 2004 2005

 


:: Query 5a ::

Query:
INSERT INTO Wine
VALUES (15, '1999', 'E. Guigal Châtaeuneuf-du-Pape', 4, 4, '750 ml', 30, null, #11/30/2002#, #6/30/2003#, 2005, 2015);

Analysis: I would like to insert the following information:
Wine_ID: 15
Vintage_yr: 1999
Wine_name: E. Guigal Châtaeuneuf-du-Pape
Wine_qty: 4
Left_qty: 4
Volume: 750 ml
Wine_amt: $30
Harvest_date: unknown
Issue_date: 11/30/2002
Buy_date: 6/30/2003
BegDrink_yr: 2005
EndDrink_yr: 2015

Wine_ID Vintage_yr Wine_name Wine_qty Left_qty Volume Wine_amt Harvest_date Issue_date Buy_date BegDrink_yr EndDrink_yr
15 1999 E. Guigal Châtaeuneuf-du-Pape 4 4 750 ml $30.00   11/30/2002 6/30/2003 2005 20015

 


:: Query 5b ::

Query:
INSERT INTO Wine ( Vintage_yr, Wine_name, Wine_qty, Left_qty, Volume, Harvest_date, Buy_date, BegDrink_yr, EndDrink_yr ) VALUES ('2001', 'Justin Justification', 1, 1, '750 ml', #10/8/2001#, #11/4/2003#, 2006, 2008);

Analysis: I would like to insert the following information:
Vintage_yr: 2001
Wine_name: Justin Justification
Wine_qty: 1
Left_qty: 1
Volume: 750 ml
Harvest_date: 10/8/2001
Buy_date: 11/4/2003
BegDrink_yr: 2006
EndDrink_yr: 2008

Wine_ID Vintage_yr Wine_name Wine_qty Left_qty Volume Wine_amt Harvest_date Issue_date Buy_date BegDrink_yr EndDrink_yr
  2001 Justin Justification 1 1 750 ml   10/8/2001   11/4/2003 2006 2008

 


:: Extra Credit 1a (Distinct, with 1 column) ::

Query:
SELECT DISTINCT Vintage_yr
FROM Wine;

Analysis: I would like to select only one of each value in the Vintage_yr column.

Vintage_yr
1999
2000
2001
2002
Non-Vintage

 


:: Extra Credit 1b (Distinct, with 2 columns) ::

Query:
SELECT DISTINCT Left_qty, EndDrink_yr
FROM Wine
WHERE EndDrink_yr Is NOT Null;

Analysis: I would like to select unique combinations of Left_qty and EndDrink_yr columns to see how many bottles needs to be consumed by a certain ending year (where EndDrink_yr is not unknown).

Left_qty EndDrink_yr
1 2003
1 2005
1 2008
1 2010
2 2004
4 2008
12 2005

 


:: Extra Credit 2 (Datediff) ::

Query:
SELECT Wine_name, datediff("m",Harvest_date,Issue_date) AS Months_aged
FROM Wine
WHERE Harvest_date And Issue_date Is Not Null;

Analysis: I would like to see a list of wines and the number of months it aged from harvest time (Harvest_date) to release time (Issue_date) where the Harvest_date and Issue_date is not null.

Wine_name Months_aged
Justin Isosceles 30
Justin Cal Ital 7

 


:: Extra Credit 3 (Dateadd) ::

Query:
SELECT Vintage_yr, Wine_name, Buy_date, DateAdd("d",30,[Buy_date]) AS Month_after
FROM Wine
WHERE Buy_date>#10/1/2003#;

Analysis: Adding 30 days to latest purchases (Buy_date later than 10/1/03) estimates when the credit card charges will be reflected on monthly bill.

Vintage_yr Wine_name Buy_date Month_after
2001 Justin Malbec 11/4/03 12/4/2003
2002 Justin Obtuse 11/4/2003 12/4/2003
2001 Justin Cabernet Sauvignon 11/4/2003 11/4/2004
Non-vintage Korbel Moscato Frizzante 10/25/2003 11/24/2003
2001 Justin Zinfandel 11/4/2003 12/4/2003
2001 Justin Petit Verdot 11/4/2003 12/4/2003
Non-vintage Korbel Rouge 10/25/2003 11/24/2003