求一条MYSQL语句

wwwzrccom 2009-12-28 07:30:17
有三张表,
课程: course(cid 主键自增,cname)
问题:topic(tid 主键自增,cid,tname)
回答:revert(rid 主键自增,tid,rname)
求sql:每个课程下的问题数,每个课程下的回答数
...全文
180 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengyuanfa 2009-12-28
  • 打赏
  • 举报
回复

SELECT
c.cid,
COUNT( t.tid ) AS tid_counts,
COUNT( r.rid ) AS rid_counts
FROM
course c
LEFT JOIN topic t ON c.cid = t.cid
LEFT JOIN revert r ON t.tid = r.tid
GROUP BY
c.cid
a7945127 2009-12-28
  • 打赏
  • 举报
回复
up
sunnylyy 2009-12-28
  • 打赏
  • 举报
回复
select A.cid, count(A.tid), sum(B.rcount)
from topic A, (select tid, count(rid) as rcount from revert group by tid)B
where A.tid = B.tid group by A.cid

手写的,不保证一定正确。
存在666 2009-12-28
  • 打赏
  • 举报
回复
进来看下,学习!
wenjjing2lianee 2009-12-28
  • 打赏
  • 举报
回复
顶一个
wwwzrccom 2009-12-28
  • 打赏
  • 举报
回复
用一条语句
sunnylyy 2009-12-28
  • 打赏
  • 举报
回复
1. select cid, count(tid) from topic group by cid

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧