mysql多表查询查询排序
有 ask 问题表和 answer回答表回答表中的ask_id和 ask表中的id对应
1、查询
/*
查询回答了的
*/
select a.id,a.title,count(b.ask_id) as num from phome_ecms_ask a,phome_ecms_answer b where a.id=b.ask_id group by a.id  order by num desc
2、将ask问题表中的问题按回答数量排序mysql group by order by
/*
查询所有的问题按回答数排序
*/
select a.id,a.title,count(b.ask_id) as num from phome_ecms_ask a left join phome_ecms_answer b on a.id=b.ask_id group by a.id  order by num desc

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。