-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.txt
116 lines (104 loc) · 2.79 KB
/
sql.txt
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
#!/mnt/c/Users/Public/Documents/TKOM/interpreter
fun iterable1(table1: Map<String, int>, table2: Map<String, int>): Iterable<Tuple<String, int, int>> {
return SELECT
db1.key AS key,
db1.value AS first,
db2.value AS second
FROM table1 AS db1
JOIN table2 AS db2
ORDER BY db2.value DESC, db1.value ASC;
}
fun iterable2(table1: Map<String, int>, table2: Map<String, int>): Iterable<Tuple<String, int, int>> {
return SELECT
db1.key AS key,
db1.value AS first,
db2.value AS second
FROM table1 AS db1
JOIN table2 AS db2 ON db1.key == db2.key
ORDER BY db2.value, db1.value;
}
fun iterable3(table1: Map<String, int>, table2: Map<String, int>): Iterable<Tuple<String, int, int>> {
return SELECT
db1.key AS key,
db1.value AS first,
db2.value AS second
FROM table1 AS db1
JOIN table2 AS db2 ON db1.key == db2.key
WHERE db1.value > db2.value
ORDER BY db2.value, db1.value;
}
fun iterable4(table1: Map<String, int>, table2: Map<String, int>): Iterable<Tuple<int, int>> {
return SELECT
db1.value AS first,
db2.value AS second
FROM table1 AS db1
JOIN table2 AS db2 ON db1.key == db2.key
GROUP BY db1.value, db2.value
ORDER BY db2.value, db1.value;
}
fun iterable5(table1: Map<String, int>, table2: Map<String, int>): Iterable<Tuple<int, int>> {
return SELECT
db1.value AS first,
db2.value AS second
FROM table1 AS db1
JOIN table2 AS db2 ON db1.key == db2.key
GROUP BY db1.value, db2.value
HAVING db1.value + db2.value > db1.value * db2.value
ORDER BY db2.value, db1.value;
}
fun main() {
Map<String, int> table1 = [
"key_0" : 1,
"key_1" : 1,
"key_2" : 2,
"key_3" : 3,
"key_4" : 4,
"key_5" : 5,
"key_6" : 6,
"key_7" : 7,
"key_8" : 8,
"key_9" : 9
];
Map<String, int> table2 = [
"key_0" : 9,
"key_1" : 9,
"key_2" : 8,
"key_3" : 7,
"key_4" : 6,
"key_5" : 5,
"key_6" : 4,
"key_7" : 3,
"key_8" : 2,
"key_9" : 1
];
print("JOIN + ORDER BY");
for (Tuple<String, int, int> entry : iterable1(table1, table2)) {
print(@String entry.first);
print(@String entry.second);
print("");
}
print("JOIN ON + ORDER BY");
for (Tuple<String, int, int> entry : iterable2(table1, table2)) {
print(@String entry.first);
print(@String entry.second);
print("");
}
print("JOIN ON + WHERE + ORDER BY");
for (Tuple<String, int, int> entry : iterable3(table1, table2)) {
print(@String entry.first);
print(@String entry.second);
print("");
}
print("JOIN ON + GROUP BY + ORDER BY");
for (Tuple<int, int> entry : iterable4(table1, table2)) {
print(@String entry.first);
print(@String entry.second);
print("");
}
print("JOIN ON + GROUP BY + HAVING + ORDER BY");
for (Tuple<int, int> entry : iterable5(table1, table2)) {
print(@String entry.first);
print(@String entry.second);
print("");
}
}