-4

エラーがどこにあるのかわからないので、助けてください:)

SELECT a.*,b.*,users.*,
    (SELECT msg_text FROM message_private p 
     WHERE p.group_id=a.group_id ORDER BY occured_at DESC LIMIT 1) as message,
    (SELECT COUNT(f.profile_id) as countf from message_view f WHERE f.profile_id = 'sN07X2' AND f.id_group = b.group_id) 
FROM message_group a
JOIN message_group b ON a.group_id=b.group_id
INNER JOIN users ON users.profile_id = b.profile_id
WHERE a.profile_id = 'sN07X2'
AND b.profile_id != a.profile_id AND countf != 0 ORDER BY a.message_group_id DESC LIMIT 9
4

2 に答える 2

0

countf問題は、サブクエリ定義し、where句でそれを参照しようとしていることです。as countf代わりに、外側の select を使用してhaving句を使用する必要があります。

SELECT a.*,b.*,users.*,
    (SELECT msg_text FROM message_private p 
     WHERE p.group_id=a.group_id ORDER BY occured_at DESC LIMIT 1) as message,
    (SELECT COUNT(f.profile_id) as countf from message_view f WHERE f.profile_id = 'sN07X2' AND f.id_group = b.group_id
   ) as countf
FROM message_group a
JOIN message_group b ON a.group_id=b.group_id
INNER JOIN users ON users.profile_id = b.profile_id
WHERE a.profile_id = 'sN07X2'
AND b.profile_id != a.profile_id
having countf <> 0
ORDER BY a.message_group_id DESC LIMIT 9
于 2013-07-01T14:40:43.743 に答える