此语句是什么意思请详细回答

qq_29845565 2015-12-11 02:18:01
此段语句是正确的,但其中一部分不知道是什么意思,语句如下:
convert(decimal(5,2),count(*)*100/(select count(*) from a where id=b.id)) c
其中的(select count(*) from a where id=b.id) 不明白,不是应该写成(select count(*) from a,b where a.id=b.id) 吗,但改了又不正确,请详细解释,多谢。
...全文
197 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feihong0233 2015-12-13
  • 打赏
  • 举报
回复
select count(*) from a where id=b.id 是子查询,在b表查询内,如 SELECT id, (select count(*) from a where id=b.id) AS c FROM b 代表查询a表内id为b表当前行id列值的记录数量,你可以理解b表在执行SELECT语句的时候逐行扫描传送id给子查询
qq_29845565 2015-12-11
  • 打赏
  • 举报
回复
因为b表中id有多个,是相当于按b表中的id分组,然后分别统计a表中的 数量吗?
qq_29845565 2015-12-11
  • 打赏
  • 举报
回复
引用 3 楼 u010192842 的回复:
select count(*) from a where id=b.id 解释:这个是b表的当前id对应在a表中的数量,类似于按id汇总了。 select count(*) from a,b where a.id=b.id 解释:这个是a和b关联后的总数量。
b 表中有好几个不同的id,是分别按b表中的id对a表进行汇总吗?因为有好几个id,这一条语句是属于循环执行的吗?
Yole 2015-12-11
  • 打赏
  • 举报
回复
select count(*) from a where id=b.id 解释:这个是b表的当前id对应在a表中的数量,类似于按id汇总了。 select count(*) from a,b where a.id=b.id 解释:这个是a和b关联后的总数量。
qq_29845565 2015-12-11
  • 打赏
  • 举报
回复
就是想知道 select count(*) from a where id=b.id 是什么意思,正常是不是应该这么写吗 select count(*) from a,b where a.id=b.id 有什么区别呢
Yole 2015-12-11
  • 打赏
  • 举报
回复
上文中应该有b表吧~~ 写全了再看。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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