MySQL Concat和GROUP BY

时间:2013-11-07 20:31:53

标签: mysql sql database

我有2个表:PeopleWritings。我想获得编写最多书籍的3个人的名单。

表: enter image description here

我想获得大多数书籍的前三名(书籍=主题)。他们应该从最多到最少订购(我的意思是那3个人)。

我试着这样做:

SELECT People.Name, People.Secondname,     
  People.City, COUNT( Writings.Author)  AS Kiekis       
FROM Writings, People 
WHERE  CONCAT (People.Name, ' ',People.Secondname) = Writings.Author 
GROUP BY Kiekis DESC LIMIT 3; 

1 个答案:

答案 0 :(得分:1)

SELECT Author, COUNT(*)
FROM People, Writings 
WHERE CONCAT (People.Name, ' ',People.Secondname) = Writings.Author 
GROUP BY Author 
ORdER BY COUNT(*) DESC 
LIMIT 3

但桌子之间非常奇怪的连接,我的意思是在第一张表中使用author_id会更好。