此段语句是正确的,但其中一部分不知道是什么意思,语句如下:
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) 吗,但改了又不正确,请详细解释,多谢。
...全文
1976打赏收藏
此语句是什么意思请详细回答
此段语句是正确的,但其中一部分不知道是什么意思,语句如下: 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) 吗,但改了又不正确,请详细解释,多谢。
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给子查询