-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage_examples.sql
173 lines (153 loc) · 5.66 KB
/
usage_examples.sql
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
** Date Time functions:
** http://www.sqlite.org/lang_datefunc.html
** Math:
** http://www.sqlite.org/lang_aggfunc.html
**
** View:
** https://sqlite.org/lang_createview.html
*/
-- datetime start of given month
sqlite> SELECT datetime('now','start of year','+5 month');
2017-06-01 00:00:00
-- datetime end of given month
sqlite> SELECT datetime('now','start of year','+6 month', '-1 second');
2017-06-30 23:59:59
-- unix start of given month
sqlite> SELECT strftime('%s','now','start of year','+5 month');
1496275200
-- datetime end of given month
sqlite> SELECT datetime('now','start of year','+6 month', '-1 second');
2017-06-30 23:59:59
-- unix start of previous month
sqlite> SELECT strftime('%s','now','start of month','-1 month');
1504224000
-- unix end of previous month
sqlite> SELECT strftime('%s','now','start of month','-1 second');
1506815999
-- list of Players ids successfully buying in current month:
SELECT Auctions.nr_top_bidder FROM Auctions
WHERE Auctions.unix > strftime('%s','now','start of month')
GROUP BY Auctions.nr_top_bidder ORDER BY Auctions.nr_top_bidder ASC;
-- as above, with Player name:
SELECT Players.nr, Players.name
FROM Auctions INNER JOIN Players
ON Players.nr = Auctions.nr_top_bidder
WHERE Auctions.unix > strftime('%s','now','start of month')
GROUP BY Auctions.nr_top_bidder ORDER BY Players.name ASC;
-- ...as above: named Best Buyers in current month sorted by Gold spend:
SELECT Players.nr,
Players.name,
sum(Auctions.sell_price) AS sell_total_value
FROM Auctions
INNER JOIN Players
ON Players.nr = Auctions.nr_top_bidder
WHERE Auctions.unix > strftime('%s', 'now', 'start of month')
GROUP BY Auctions.nr_top_bidder
ORDER BY sell_total_value DESC;
-- named TOP10 Best Sellers in current year sorted by Total Gold Gain:
SELECT Players.nr,
Players.name,
sum(Auctions.sell_price) AS sell_total_value
FROM Auctions
INNER JOIN Players
ON Players.nr = Auctions.nr_issuer
WHERE ( Auctions.unix > strftime('%s', 'now', 'start of year')
AND Auctions.nr_top_bidder IS NOT NULL )
GROUP BY Auctions.nr_issuer
ORDER BY sell_total_value DESC
LIMIT 10;
-- named TOP Best Sellers in current year sorted by Auctions amount, Total Gold Gain (just for ref):
SELECT count(*) AS auctions_amount,
Players.name,
sum(Auctions.sell_price) AS sell_total_value
FROM Auctions
INNER JOIN Players
ON Players.nr = Auctions.nr_issuer
WHERE ( Auctions.unix > strftime('%s', 'now', 'start of year')
AND Auctions.nr_top_bidder IS NOT NULL )
GROUP BY Players.nr
ORDER BY auctions_amount DESC;
-- total Market Gold circulation in current month:
SELECT sum(Auctions.sell_price) AS total_circulation
FROM Auctions
WHERE (Auctions.unix > strftime('%s','now','start of month') AND Auctions.nr_top_bidder IS NOT NULL);
-- total Items sold in current month:
SELECT count(*) AS total_sold_items
FROM Auctions
WHERE (Auctions.unix > strftime('%s','now','start of month') AND Auctions.nr_top_bidder IS NOT NULL);
-- total items circulated on Market in current month:
SELECT count(*)
FROM Auctions INNER JOIN Items
ON Items.nr = Auctions.nr_item
WHERE Auctions.unix > strftime('%s','now','start of month')
GROUP BY Items.nr;
-- total Auctions in current month:
SELECT count(*)
FROM Auctions
WHERE Auctions.unix > strftime('%s','now','start of month');
-- counting Items Qualities from beginning of the server,
-- INNER JOIN with Auctions is neccessary for optional Auction.unix
SELECT Count(items.q) AS item_qualities,
items.q
FROM auctions
INNER JOIN items
where auctions.nr_item = items.nr
GROUP BY items.q;
-- looking for MAX Stat of Increase damage (stat nr:4):
SELECT Items.nr,
Items.type,
Items.q,
CASE
WHEN (Items.stat_a = 4 AND Items.stat_b <> 4) THEN Items.stat_a_value
WHEN (Items.stat_a = 4 AND Items.stat_b = 4) THEN (Items.stat_a_value + Items.stat_b_value)
ELSE Items.stat_b_value
end AS item_concrete_value
FROM Items
WHERE ( Items.stat_a = 4
OR Items.stat_b = 4 )
ORDER BY item_concrete_value DESC;
-- looking for MAX Stat of 'Increase damage' (stat nr:4) with named Items:
SELECT Items.nr,
ItemTypes.type,
Items.q,
CASE
WHEN (Items.stat_a = 4 AND Items.stat_b <> 4) THEN Items.stat_a_value
WHEN (Items.stat_a = 4 AND Items.stat_b = 4) THEN (Items.stat_a_value + Items.stat_b_value)
ELSE Items.stat_b_value
end AS item_concrete_value
FROM Items
INNER JOIN Itemtypes
ON Items.type = ItemTypes.nr
WHERE ( Items.stat_a = 4
OR Items.stat_b = 4 )
ORDER BY item_concrete_value DESC;
-- counting types of exposed named Items:
SELECT ItemTypes.type,
Count(*) AS occurencies
FROM Auctions
INNER JOIN Items
ON Auctions.nr_item = Items.nr
INNER JOIN Itemtypes
ON Items.type = ItemTypes.nr
GROUP BY Itemtypes.type
ORDER BY occurencies DESC;
-- counting types of circulated named Items:
SELECT ItemTypes.type,
Count(*) AS occurencies
FROM Auctions
INNER JOIN Items
ON Auctions.nr_item = Items.nr
INNER JOIN Itemtypes
ON Items.type = ItemTypes.nr
WHERE Auctions.nr_top_bidder IS NOT NULL
GROUP BY Itemtypes.type
ORDER BY occurencies DESC;
-- counting qualities of exposed Items:
SELECT Items.q,
Count(*) AS occurencies
FROM Auctions
INNER JOIN Items
ON Auctions.nr_item = Items.nr
GROUP BY Items.q
ORDER BY Items.q ASC;