2012-06-30 102 views
0
account_users 
----- 
id | primary_key 

posts 
----- 
post_id | primary_key 
author | foreign key to account_users.id 

比方說,我有2個表格。 account_users有用戶。帖子包含帖子。如何使用count()運行select查詢?

如何選擇帖子數(*)超過5的所有用戶?

回答

0

嘗試下面的查詢該

SELECT au.*,p.* 
FROM account_users au 
INNER JOIN posts p 
ON p.account_users.id = au.id 
GROUP BY p.post_id 
HAVING count(*) > 5 
0

@Timex

嘗試。

Select au.ID from account_users au 
inner join posts p on au.ID = p.author 
Group By au.ID 
having COUNT(p.post_id) > 5