2012-06-20 27 views
0

我正在編寫查詢來計算數據庫表中不同值的數量。所以我寫了查詢爲:將COUNT和DISTINCT關鍵字一起使用來計算不同的值

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

誰能解釋我缺少什麼?

+0

看起來不錯。確保你沒有製表符 – Bohemian

+0

它只是'distinct'後面的空格。它現在工作。不管怎麼說,多謝拉。 –

回答

3

刪除count與左括號之間的空格。

select count(distinct user_id) as unique_users from 1_time_access; 
相關問題