سلام
امیدوارم این کد کمک کنه
در مورد راهنمایی کد هم فقط اینو بدون که دستور داخل پرانتز بعد از Cross Apply برای هر رکورد Select بیرونی یه بار اجرا میشه ... پس کلا زیاد رو سرعت و پرفومنسش حساب نکن ... یه نکته هم در مورد نام گذاری فیلدهای جدولت بیشتر دقت کن مثلا هم جدول Comment فیلد ID داره هم Rate بهتره که اسمشون مشخص باشه ... CommentID و ...
SELECTtop 6 TBLNews.NewsID, TBLNews.Title, TBLNews.Abstract, TBLNews.Contents, TBLNews.AddDate, TBLNews.img
,isnull(convert(nvarchar(50),Sum(RatingPost.Rating)),'0')AS SumOfRating
,isnull(convert(nvarchar(50),Count(RatingPost.PostID)),'0')AS CountOfPostID
, C.countComments
FROM TBLNews LeftOuterJoin RatingPost ON TBLNews.NewsID = RatingPost.PostID
cross apply(Selectdistinctcount(id)as countComments from comments where postid=tblnews.newsid) c
GROUPBY TBLNews.NewsID, TBLNews.Title, TBLNews.Abstract, TBLNews.Contents, TBLNews.AddDate, TBLNews.img,c.countComments ORDERBY NewsID DESC