-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_data_query.sql
More file actions
92 lines (72 loc) · 2.63 KB
/
Simple_data_query.sql
File metadata and controls
92 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--*************************************************************************--
-- Title: Assignment03
-- Author: Byung Su Jung
-- Desc: This file demonstrates how to select data from a database
-- Change Log: When,Who,What
-- 2017-06-26,ByungSuJung,Created File
--**************************************************************************--
/********************************* Questions and Answers *********************************/
-- Data Request: 0301
-- Date: 1/1/2020
-- From: Jane Encharge CEO
-- Request: I want a list of customer companies and their contact people
-- Needed By: ASAP
SELECT CompanyName, ContactName
FROM Northwind.dbo.Customers
GO
-- Data Request: 0302
-- Date: 1/2/2020
-- From: Jane Encharge CEO
-- Request: I want a list of customer companies and their contact people, but only the ones in US and Canada
-- Needed By: ASAP
SELECT CompanyName, ContactName, Country
FROM Northwind.dbo.Customers
WHERE Country = 'USA' or Country = 'Canada'
ORDER BY Country, CompanyName;
GO
-- Data Request: 0303
-- Date: 1/2/2020
-- From: Jane Encharge CEO
-- Request: I want a list of products, their standard price and their categories. Order the results by Category Name
-- and then Product Name, in alphabetical order
-- Needed By: ASAP
SELECT CategoryName, ProductName, [Standard Price] = FORMAT (UnitPrice, 'C', 'en-us')
FROM Northwind.dbo.Products
JOIN Northwind.dbo.Categories
ON Products.CategoryID = Categories.CategoryID
ORDER BY CategoryName, ProductName
GO
-- Data Request: 0304
-- Date: 1/3/2020
-- From: Jane Encharge CEO
-- Request: I want a list of how many customers we have in the US
-- Needed By: ASAP
SELECT [Count] = COUNT(CustomerID), [Country] = 'USA'
FROM Northwind.dbo.Customers
WHERE Country = 'USA'
GO
-- Data Request: 0305
-- Date: 1/4/2020
-- From: Jane Encharge CEO
-- Request: I want a list of how many customers we have in the US and Canada, with subtotals for each
-- Needed By: ASAP
SELECT [Count] = COUNT(CustomerID) ,[Country] = 'USA'
FROM Northwind.dbo.Customers
WHERE Customers.Country = 'USA'
UNION
SELECT [Count] = COUNT(CustomerID), [Country] = 'Canada'
FROM Northwind.dbo.Customers
WHERE Customers.Country = 'Canada'
GO
-- Data Request: 0306
-- Date: 1/4/2020
-- From: Jane Encharge CEO
-- Request: I want a list of products ordered by the Price highest to the lowest. Only products that have a price Greater than $100.
-- Needed By: ASAP
SELECT *
FROM Northwind.dbo.Products
JOIN Northwind.dbo.[Order Details]
ON Products.ProductID = [Order Details].ProductID
WHERE Products.UnitPrice > 100
ORDER BY Products.UnitPrice DESC
/***************************************************************************************/