gongsi(公司表)
id:
summary:
artices(文章表)
id:
gongsi_id:
content:
公司排序(以文章总数进行降序排序)
[code="java"]
select G.id,G.summary,count(A.id) as c from gongsi as G join artices as A on A.gongsi_id = G.id order by c
[/code]
你试试
[code="sql"]
select id, summary
from (
select G.id, G.summary, count(A.id) cnt
from gongsi as G join artices as A on A.gongsi_id = G.id
group by G.id
) t
order by cnt
[/code]
[code="java"]
select id, summary
from (
select G.id, G.summary, count(A.id) cnt
from gongsi as G inner join artices as A on A.gongsi_id = G.id
group by G.id
) t
order by cnt desc
[/code]