作者cutekid (可爱小孩子)
看板Database
标题Re: [MySQL] Select the row which one of the ...
时间Mon Jan 22 15:43:31 2018
with tb1 as (
select Id,count(*) as cnt
from example
group by Id
)
select t1.No,t1.Name
from example t1
inner join tb1 on t1.No = t2.Id
order by t2.cnt desc
※ 引述《rrr0832 (rrr0832)》之铭言:
: If there is a table name "example" like below:
: http://i.redwh.al/Ef.png
: How do I select the name which "No" has the most occurrence in other rows' "Id
: "?
: Here's my try:
: http://i.redwh.al/Ld.png
: The result should be like this:
: http://i.redwh.al/T7.png
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.61.233.210
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1516607013.A.C76.html