0

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

表: 在此处输入图像描述

我想得到写书最多的前 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; 
4

1 回答 1

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 会更好。

于 2013-11-07T20:40:15.580 回答