【问题标题】:Using COUNT and DISTINCT keywords together to count distinct values一起使用 COUNT 和 DISTINCT 关键字来计算不同的值
【发布时间】:2012-06-20 05:18:26
【问题描述】:

我正在编写查询来计算数据库表中不同值的数量。所以我把查询写成:

select count ( distinct user_id ) as unique_users from 1_time_access;

我遇到错误

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'distinct user_id ) as unique_users from 1_time_access' at line 1

谁能解释我错过了什么?

【问题讨论】:

  • 看起来不错。确保其中没有制表符
  • 就是distinct后面的空格。它现在起作用了。无论如何,谢谢。

标签: mysql sql database count distinct


【解决方案1】:

删除count 和左括号之间的空格。

select count(distinct user_id) as unique_users from 1_time_access;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多