forked from mattm401/collabortweet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createSchema.sql
57 lines (49 loc) · 1.29 KB
/
createSchema.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
CREATE TABLE IF NOT EXISTS tasks (
taskId INTEGER PRIMARY KEY,
taskName TEXT,
question TEXT,
taskType INTEGER
);
CREATE TABLE IF NOT EXISTS users (
userId INTEGER PRIMARY KEY,
screenname TEXT UNIQUE NOT NULL,
fname TEXT,
lname TEXT
);
CREATE TABLE IF NOT EXISTS elements (
elementId INTEGER PRIMARY KEY,
elementText TEXT NOT NULL,
taskId INTEGER NOT NULL,
externalId INTEGER
);
CREATE TABLE IF NOT EXISTS labels (
labelId INTEGER PRIMARY KEY,
labelText TEXT NOT NULL,
taskId INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS elementLabels (
elementLabelId INTEGER PRIMARY KEY,
elementId INTEGER NOT NULL,
labelId INTEGER NOT NULL,
userId INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS pairs (
pairId INTEGER PRIMARY KEY,
taskId INTEGER NOT NULL,
leftElement INTEGER NOT NULL,
rightElement INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS comparisons (
compareId INTEGER PRIMARY KEY,
pairId INTEGER NOT NULL,
userId INTEGER NOT NULL,
decision INTEGER NOT NULL
);
CREATE VIEW pairChoices AS SELECT
els.elementId AS elementId, els.taskId as taskId, COUNT(cps.compareId) AS counter
FROM
elements els
LEFT OUTER JOIN pairs prs ON
els.elementId = prs.leftElement OR els.elementId = prs.rightElement
LEFT OUTER JOIN comparisons cps ON cps.pairId = prs.pairId
GROUP BY els.elementId;