gpt4 book ai didi

sql - 从连接表中删除重复行

转载 作者:行者123 更新时间:2023-12-03 05:02:23 24 4
gpt4 key购买 nike

我有以下sql查询

SELECT m.School, c.avgscore 
FROM postswithratings c
join ZEntrycriteria on c.fk_postID= m.schoolcode

提供以下结果

School| avgscore
xyz | 5
xyz | 5
xyz | 5
abc | 3
abc | 3
kkk | 1

我的问题是如何删除这些重复项并仅获得以下内容。

 School| avgscore
xyz | 5
abc | 3
kkk | 1

我尝试过

   SELECT m.School, c.avgscore 
FROM postswithratings c
join ZEntrycriteria on c.fk_postID= m.schoolcode
group by m.School

但它给了我以下错误

"Column 'postswithratings.avgscore' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."

最佳答案

没必要把事情搞复杂。只需选择:

SELECT m.School, c.avgscore 
FROM postswithratings c
join ZEntrycriteria on c.fk_postID= m.schoolcode
group by m.School, c.avgscore

SELECT DISTINCT m.School, c.avgscore 
FROM postswithratings c
join ZEntrycriteria on c.fk_postID= m.schoolcode

关于sql - 从连接表中删除重复行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43134054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com