-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViews.sql
More file actions
72 lines (52 loc) · 1.42 KB
/
Copy pathViews.sql
File metadata and controls
72 lines (52 loc) · 1.42 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
USE CloudComputingDatabase_Team01;
/* View describing frequency of activity against each server location. */
CREATE VIEW ServerLocationSaleMaster AS
SELECT
DISTINCT sl.ServerLocation,
COUNT(atr.ActivityID) as 'Activity Frequency'
FROM
ServerLocation sl
LEFT JOIN MachineImage mi ON
sl.ServerID = mi.ServerID
LEFT JOIN SaleMaster sm ON
sm.MachineImageID = mi.MachineImageID
LEFT JOIN ActivityTracker atr ON
sm.MasterID = atr.MasterId
GROUP BY
sl.ServerLocation;
SELECT
*
FROM
ServerLocationSaleMaster;
-- Total amount of Transactions per user
CREATE VIEW UserInfoTransactions2
AS
SELECT ui.UserID, ui.Firstname, ui.Lastname, sum(t.Amount) AS [TotalSum]
FROM SaleMaster sm
LEFT JOIN UserInfo ui ON sm.UserID = ui.UserID
LEFT JOIN BillingInformation bi ON sm.MasterID = bi.MasterID
LEFT JOIN Transactions t ON bi.BillingID = t.BillingID
GROUP BY ui.UserID, ui.Firstname, ui.Lastname ;
-- Display View
SELECT * from UserInfoTransactions2;
/* Report showing details of subscribed images for each user. */
SELECT
DISTINCT sm.UserID, ui.FirstName, ui.LastName,
STUFF ((
SELECT
', ' + RTRIM(CAST(MasterID as char))
FROM
SaleMaster
WHERE
UserID = sm.UserID
GROUP BY
MasterID
ORDER BY
sm.MasterID FOR XML PATH ('')), 1, 1, '') AS 'Subscribed Image ID'
FROM
SaleMaster sm
LEFT JOIN UserInfo ui ON sm.UserID = ui.UserID
GROUP BY
sm.UserID, sm.MasterId, ui.FirstName, ui.LastName
ORDER BY
sm.UserID;