请参阅所附的表格图像。
我有问题:
查找2016年借用最多的前5个职业
我拥有的代码:
select c.occupation, count(*) no_mostborrow
from client c
Inner Join client c on c.clientID = b.clientID
where b.borrowDate >= '2016-01-01' and b.borrowDate < '2017-01-01'
group by c.clientoccupation, c.clientid
order by count(*) asc
limit 5
我觉得我在这里想念什么,但是我不确定。我确定我已经完全离开了。非常感谢您的宝贵时间。
要回答您的问题,只需要occupation
中的group by
。并且join
必须正确:
select c.occupation, count(*) as no_mostborrow
from client c join
borrower b
on c.clientid = b.clientid
where b.borrowDate >= '2016-01-01' and b.borrowDate < '2017-01-01'
group by c.clientoccupation
order by count(*) asc
limit 5