在SQL Server中使用联接而不是子查询
|
大家好,我与我有以下餐桌关系,
并且我正在存储过程中编写以下嵌套查询
. Select useremail,fullname,city,[state], allowAlerts,allowLetters,aboutMe,avatar,dateregistered,
(Select COUNT(*) from blog_info where blog_info.userId = @userId)as blogCount,
(Select count(*) from blog_info where blog_info.isfeatured = 1 AND blog_info.userId = @userId)as featuredCount,
(Select COUNT(*) from blog_comments where blog_comments.userId = @userId)as commentsCount,
(Select COUNT(*) from forum where forum.createdby = @userId) as forumCount,
(Select COUNT(*) from forumresponse where forumresponse.userId = @userId)as responseCount
from user_info where _id = @userId.
我想将这个嵌套查询替换为ues Joins查询。
请帮助我实现这一目标。
提前致谢
没有找到相关结果
已邀请:
3 个回复
曝匿弄罚
(以此类推,对您原来拥有的每个子查询执行类似的联接)
对不起,没用的格式! 注意:查询引擎可能足够聪明,可以对两个查询使用相同的执行计划,因此您不一定会看到改进
体悉
抬澈帅沮