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.
1条回答 默认 最新
- dongpeng7744 2010-04-24 16:47关注
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.解决 无用评论 打赏 举报