我的查詢:計數數據
"SELECT id
FROM user_follow
WHERE user_id IN(3,6) AND follow_id NOT IN(3,6)
GROUP BY follow_id";
,它顯示:
[users] => Array
(
[0] => Array
(
[id] => 20
)
[1] => Array
(
[id] => 9
)
[2] => Array
(
[id] => 19
)
)
我需要統計數據(在這個例子中查詢必須歸還3的結果)
我試過COUNT(ID)但結果對我不好。
結果:
[0] => Array
(
[count(id)] => 1
)
我試圖SELECT COUNT(1)
結果:
[0] => Array
(
[count(1)] => 1
)
[1] => Array
(
[count(1)] => 2
)
[2] => Array
(
[count(1)] => 1
)
還沒不是一數(3)。我想是這樣的[用戶] => 3
你是什麼意思的「效果不好」?你有錯誤嗎?不是正確的號碼嗎? – jprofitt 2012-01-29 00:14:50
刪除'GROUP BY'然後....並只是'SELECT COUNT(DISTINCT id)' – Wrikken 2012-01-29 00:15:56
我不能刪除GROUP BY follow_id,因爲http://stackoverflow.com/questions/9049401/select-all-my -and-my-friends-friends-except-us-both-sql此組防止顯示重複的朋友 – Viktors 2012-01-29 00:35:14