此 SQL 语句存在语法错误和逻辑错误。

首先,子查询应该用括号括起来,正确写法应该是:

select p.id,p.name,(select count(f_productId) from imgs i where i.f_prooductId=p.id) from product p

其次,子查询中的表别名应该与主查询中的表别名保持一致,正确写法应该是:

select p.id,p.name,(select count(f_productId) from imgs i where i.f_productId=p.id) from product p

最后,由于子查询中使用了聚合函数 count,需要使用别名来命名结果列,正确写法应该是:

select p.id,p.name,(select count(f_productId) from imgs i where i.f_productId=p.id) as img_count from product p
排错select pidpnamecountselect f_productId from imgs i where if_prooductId=pid from product p

原文地址: https://www.cveoy.top/t/topic/fVWr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录