我有2个表:People
和Writings
。我想获得编写最多书籍的3个人的名单。
表:
我想获得大多数书籍的前三名(书籍=主题)。他们应该从最多到最少订购(我的意思是那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;
答案 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会更好。