开发者

How to count unique occurences of Data in SQL

I am trying to count unique occurrences of a Client ID in the following code.

TRANSFORM Count(Res开发者_开发问答earch.Client_ID) AS CountOfClient_ID
SELECT Research.Treatment, Count(DCount("[Client_ID]","[Letter Status]")) AS [Total Letters Sent]
FROM Research INNER JOIN [Letter Status] ON Research.Client_ID = [Letter Status].Client_ID
GROUP BY Research.Treatment
PIVOT [Letter Status].Letter_Status;

The expression I think needs to be modified is:

Total Letters Sent: Count(DCount("[Client_ID]","[Letter Status]"))

The typical form for the DCount function is (expression, domain, *criteria*). I am pretty sure I need to specify, somehow, that the [Client_ID] should be unique in the criteria argument of the DCount function, but I don't know how. Is this possible?


If this query doesn't get what you want, please show us with sample data how it differs from what you want.

SELECT
    q.Treatment,
    Count(*) AS [Total Letters Sent]
FROM
    [SELECT DISTINCT
        Treatment,
        Client_ID
    FROM
        Research
    ]. AS q
GROUP BY
    q.Treatment;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜