2016-04-04 21 views
1

Ich habe zwei Tabellen.Autorennamen sortieren nach Anzahl

AUTOR

Author_ID  Author_Name    
-------------------------      
1   name 1  
2   name 2  
3   name 3 
--------------------------- 

POST

Post_ID  Author_ID 
-------------------------      
1   1  
2   1  
3   2 
4   3 
5   3 
6   3 
--------------------------- 

Ich brauche eine MySQL-Abfrage, die die Anzahl der Beiträge jeder Autor zählt hat und dann sortiert die Autoren der größten zur kleinsten.

Mein aktueller MySQL zeigt nur die Namen:

select * from AUTHOR 
where author_status = '1' ORDER BY author_name DESC 

Antwort

1
SELECT author.author_id, author.author_name, count(post.post_id) FROM AUTHOR, POST 
    WHERE (author_status = '1') 
    AND (author.author_id = post.author_id) 
GROUP BY author.author_id 
ORDER BY author.author_name DESC; 
+0

ich die ORDER BY-Linie entfernt, und das gab mir das Ergebnis, das ich suchte. Danke! –