Escolar Documentos
Profissional Documentos
Cultura Documentos
GIS-GM Professor
Niagara College
135 Taylor Road
Niagara-on-the-Lake, ON
L0S 1J0
RE: Deliverable 3: Winery Database T-SQL for GISC9303 GIS Database and Data Warehouse Concepts.
Please accept this letter as my formal submission of Deliverable 3: Winery Database T-SQL for GISC9303 GIS Database
The purpose of the assignment is to develop a basic understanding of T-SQL through designing and using a database. The
first part of the assignment is the creation of a winery database used to house winery data. The second part of the assignment
consists of 10 queries developed using T-SQL to perform various tasks within a winery database. The T-SQL document can
be located at:
X:/Students/wdrouin1/GISC9303/Deliverables/D3/DrouinWGISC9303D3Winery/DrouinWGISC9303D3Winery.sql
Should you have any concerns regarding the enclosed documents or if there are any questions please contact me at your
convivence via e-mail at winona.drouin@gmail.com or phone at (905)932-4534. I look forward to hearing from you.
Warm Regards,
W.D./w.d
Enclosures: 1.) Winery Database T-SQL Part 1 (Database Creation) and Part 2 (Database Queries)
-- Author: Winona Drouin
-- Created on: December 22, 2017
-- D3: Winery Database T-SQL for GISC 9303 - GIS Database and Data Warehouse Concepts
-- Purpose: To develop T-SQL statements to create a database and to extract both attribute and spatial
information. PART 1
USE DrouinWGISC9303D3Winery;
GO
-- Below is the creation of the winery database tables. Assisted using W3Schools.com
USE Winery
GO
--Question 1. List the top 3 wineries with the [Winery Name] and their [Website], sorted by winery name
is ascending order.
--Question 2. How many wineries are there in the database? List only a single column name as [Total
Number of Wineries].
--Question 3. Write a query to list only the [Winery Name] column for those wineries whose names
contain either 'Wine' or 'Vine' letters. Assume the database is not case-sensitive for string
operations.
--Question 4. Write a query to provide the full mailing addresses within a single column named [Mailing
Address], that includes the Winery Name, Street, City, Province, Country, PostalCode fields for the
wineries selected from the previous question (the field is separated by a comma AND a space).
--Question 5. Summarize each [Wine Variety Name] and its [Total Number of Bottles of Wines Produced]
(non-zero production). List the two columns and sort the [Total Number of Bottles of Wines Produced]
column by descending order.
--Question 6. Which winery has produced the most expensive wine per bottle? Include the [Winery Name],
[Wine Type], [Wine Variety], [Vintage Year] (with only 4-digit year), [Price per Bottle], [UTM
Easting], and [UTM Northing].
--Question 7. Retrieve the only wineries which were founded in and after 1994 with three fields:
[Winery Name], [Year Founded] (with only 4-digit year), and [Total Number of Bottles of Wines
Produced]. The queried records are sorted by the [Total Number of Bottles of Wines Produced] by
descending order.
--Question 8. Derive those wineries which have produced Chardonnay in 2001 and sort the [Total Number
of Bottles of Chardonnay Produced] in descending order. Fields included in the result are [Winery
Name], [Wine Variety Name], [Total Number of Bottles of Chardonnay Produced], and [Vintage Year] (use
only 4-digit year).
4
SELECT WineryName, WineVarietyName, BottlesProduced AS [Total Bottles of Chardonnay Produced],
YEAR(VintageYear) 'Vintage Year'
FROM tblWinery
INNER JOIN tblWineProduct ON tblWinery.WineryID=tblWineProduct.WineryID
INNER JOIN tblWineVariety ON tblWineProduct.WineVarietyID=tblWineVariety.WineVarietyID
WHERE WineVarietyName
LIKE '%Chardonnay%' AND VintageYear LIKE '%2001%'
ORDER BY [Total Bottles of Chardonnay Produced] DESC;
GO
--Question 9. Extract 4 pieces of information: [Winery Name], [Total Number of Bottles of Wines
Produced], [Weighted Average Price per Bottle], and [Total Sales] for those wineries whose total sales
are over 1 million dollars, ordered by the [Total Sales] in descending order. Assume that each winery
has sold out every bottle of their wines in stock at the price that was initially marketed.
--Question 10. Extract two wineries, including the columns of the [Winery ID], [Winery Name], and the
[Distance between Two Wineries in Metre]. These two wineries are the closest to each other in spatial
distance, i.e. they have the shortest distance in between. Display the wineries within a single record
and round the distance to the nearest integer in metre.
SELECT TOP 1
(A.WineryID+', ' + B.WineryID) AS [Winery ID], A1.WineryName+', '+ B1.WineryName) As [Winery Name],
ROUND ((SQRT((SQUARE(A.UTMNorthing-B.UTMNorthing))+SQUARE (A.UTMEasting-B.UTMEasting))), 0)
AS [Metre Distance Between Wineries]
FROM (tblWineryLocation 1 FULL OUTER JOIN tblWinery A1 ON A1.WineryID=A.WineryID), (tblWineryLocation 2
FULL OUTER JOIN tblWinery B1 ON B1.WineryID=B.WineryID)
WHERE A.WineryID<B.WineryID
ORDER BY [Metre Distance Between Wineries] ASC;
GO