0

I an trying to retrieve the distinct records using the follow SQL Statement:

SELECT count (*) FROM(
SELECT DISTINCT pv1.docid, pv2.docid 
FROM Frequency pv1
INNER JOIN Frequency pv2
ON pv1.docid = pv2.docid
AND pv1.term="transactions"
AND pv2.term="world")x;

The schema is:

CREATE TABLE Frequency (
docid VARCHAR(255),
term VARCHAR(255),
count int,
PRIMARY KEY(docid, term);

I know that there are 187 docs containing term world and 26 containing transactions.

4

1 回答 1

1

你只是想这样做吗?

SELECT 
    COUNT(DISTINCT pv1.[docid])
FROM
    Frequency AS pv1
JOIN
    Frequency AS pv2
        ON pv2.[docid] = pv1.[docid]
WHERE
    pv1.[term] = "transactions"
    AND pv2.[term] = "world"

这将返回符合您规定条件的唯一 docid 的计数。

于 2013-05-14T04:24:36.217 回答