doujia9204 2010-04-24 16:45
浏览 14

帮助MySQL获取具有不同另一列的列的计数?

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.

    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据