SHOW:
|
|
- or go back to the newest paste.
1 | -- 01. Buy the items | |
2 | ||
3 | DECLARE @AlexCash MONEY; | |
4 | DECLARE @AlexEdinburghID INT; | |
5 | DECLARE @ItemsTotalPrice MONEY; | |
6 | ||
7 | SET @AlexEdinburghID = (SELECT Id | |
8 | FROM UsersGames | |
9 | WHERE UserId = (SELECT Id FROM Users WHERE Username = 'Alex') | |
10 | AND GameId = (SELECT Id FROM Games WHERE Name = 'Edinburgh')); | |
11 | ||
12 | SET @ItemsTotalPrice = (SELECT SUM(Price) FROM Items | |
13 | WHERE Name IN | |
14 | ('Blackguard', | |
15 | 'Bottomless Potion of Amplification', | |
16 | 'Eye of Etlich (Diablo III)', | |
17 | 'Gem of Efficacious Toxin', | |
18 | 'Golden Gorget of Leoric', | |
19 | 'Hellfire Amulet')) | |
20 | ||
21 | UPDATE UsersGames | |
22 | SET Cash -= @ItemsTotalPrice WHERE Id = @AlexEdinburghID | |
23 | ||
24 | INSERT INTO UserGameItems VALUES | |
25 | ((SELECT Id FROM Items WHERE Name = 'Blackguard'), @AlexEdinburghID), | |
26 | ((SELECT Id FROM Items WHERE Name = 'Bottomless Potion of Amplification'), @AlexEdinburghID), | |
27 | ((SELECT Id FROM Items WHERE Name = 'Eye of Etlich (Diablo III)'), @AlexEdinburghID), | |
28 | ((SELECT Id FROM Items WHERE Name = 'Gem of Efficacious Toxin'), @AlexEdinburghID), | |
29 | ((SELECT Id FROM Items WHERE Name = 'Golden Gorget of Leoric'), @AlexEdinburghID), | |
30 | ((SELECT Id FROM Items WHERE Name = 'Hellfire Amulet'), @AlexEdinburghID) | |
31 | ||
32 | -- 2.Select all users in the current game with their items | |
33 | ||
34 | SELECT | |
35 | u.Username, | |
36 | g.Name, | |
37 | ug.Cash, | |
38 | i.Name AS [Item Name] | |
39 | FROM Users AS u | |
40 | INNER JOIN UsersGames AS ug | |
41 | ON ug.UserId = u.Id | |
42 | INNER JOIN Games AS g | |
43 | ON g.Id = ug.GameId | |
44 | INNER JOIN UserGameItems AS ugi | |
45 | ON ugi.UserGameId = ug.Id | |
46 | INNER JOIN Items AS i | |
47 | ON i.Id = ugi.ItemId | |
48 | WHERE g.Name = 'Edinburgh' | |
49 | ORDER BY [Item Name] |