CREATE TEMP VIEW IF NOT EXISTS Frequency_altered AS SELECT docid term

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CREATE TEMP VIEW
IF NOT EXISTS
Frequency_altered AS
SELECT docid, term, count
FROM Frequency
UNION
SELECT 'q' as docid, 'washington' as term, 1 as count
UNION
SELECT 'q' as docid, 'taxes' as term, 1 as count
UNION
SELECT 'q' as docid, 'treasury' as term, 1 as count;
SELECT row_num, col_num, SUM(value) AS value
FROM (
SELECT (a.count * b.count) AS value, a.docid as row_num, b.docid as col_num
FROM Frequency_altered a
JOIN Frequency_altered b
ON a.term = b.term
)
WHERE row_num = 'q' and col_num != 'q'
GROUP BY row_num, col_num
ORDER BY value DESC
LIMIT 1;