我有这样的SQL代码:
SELECT
TB_DataProperti.*,
TBL_Rating.ISNULL(AVG(Rating), 0) AverageRating
FROM
TB_DataProperti
INNER JOIN
TBL_Rating ON TB_DataProperti.Kode_Properti = TBL_Rating.Kode_Properti
GROUP BY
TB_DataProperti.JudulListing
ORDER BY
AverageRating DESC我知道这个错误:
Msg 8120,第16级,状态1,第3行 列'TB_DataProperti.Kode_Properti‘在select列表中无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中。
我只想使用*选择所有数据列,因为我有很多列
发布于 2017-08-24 06:37:51
问题是,您尝试在另一个table.The上使用表和组的聚合函数,规则是,如果您在另一列中使用聚合函数,那么该列应该在组by.Still中使用,尝试一下,我希望这是有用的。
SELECT
TB_DataProperti.*,
ISNULL(AVG(TBL_Rating.Rating), 0) over (partition by TBL_Rating.Kode_Properti) as AverageRating
FROM
TB_DataProperti
INNER JOIN
TBL_Rating ON TB_DataProperti.Kode_Properti = TBL_Rating.Kode_Properti
ORDER BY
AverageRating DESChttps://stackoverflow.com/questions/45853743
复制相似问题