开发者

Help with MySQL getting count of a column with distinct another column?

Hi I want to get the count of column called 'response'. But even though a user submits many responses I want it to be only considered as one. So basically I want开发者_运维问答 to get the count of 'response' with DISTINCT user_id. How can I do this? Thank you.


I'm not 100% sure I understand your table structure, but maybe you want this?

SELECT COUNT(DISTINCT userid)
FROM Table1
WHERE response IS NOT NULL

Result:

2

Test data:

CREATE TABLE table1 (userid INT NOT NULL, response NVARCHAR(100) NULL);
INSERT INTO table1 (userid, response) VALUES
(1, NULL),
(1, 'a'),
(1, 'b'),
(2, NULL),
(3, 'c');

Note: if the response column cannot be NULL, you don't need the WHERE response IS NOT NULL clause.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜