sql中的邮政编码和地址金额

sql中的邮政编码和地址金额,sql,Sql,如果之前有人问过,那么我的搜索功能就会被诅咒 select postkode, gemeente, count(postkode) as total from leveradressen where land=1 group by postkode order by postkode asc postkode是一个zipcode gemeente是镇名 我试着运行这个,但我得到了 Msg 8120, Level 16, State 1, Line 4 Column 'leveradre

如果之前有人问过,那么我的搜索功能就会被诅咒

select postkode, gemeente, count(postkode) as total 
from leveradressen 
where land=1 
group by postkode 
order by postkode asc
postkode是一个zipcode gemeente是镇名

我试着运行这个,但我得到了

Msg 8120, Level 16, State 1, Line 4
Column 'leveradressen.Gemeente' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
。。。不知道该怎么做。我知道他为什么这么做。但这是一项考察我是否能保住这份工作的任务,我在这方面完全失败了

发生的事情是,他认为有太多的地名可供选择。但每个地名都与每个zipcode匹配。从来没有任何偏差。例如,2000年将永远是安特卫普

不,我不能通过添加“groupby”来修复它,因为它就在那里,我不能使用聚合函数,因为postkode和plaatsnaam都是nvarchar

我没有主意了。

你可以使用:

select postkode, MIN(gemeente) AS gemeente, count(postkode) as total 
                 -- here goes agg function
from leveradressen 
where land=1 
group by postkode 
order by postkode asc

您也应该按
gemeente
分组。
因此:


我不知道你的意思,我不能通过添加一个“分组依据”来解决这个问题,因为它就在那里

有人问过它。通过学习搜索错误来提高搜索效率:问题的可能重复:你说2000年总是安特卫普,但安特卫普总是2000年?换句话说,这是一对一的关系?@RobertKock,是的。它们是邮政编码。x是y,y是x。一个是数字,另一个是名字。但它们是一样的。。。。。我以前试过这个,但没用。弗里克现在是怎么工作的???奇怪的太空恶魔,这就是为什么。非常感谢。
select postkode, gemeente, count(postkode) as total 
from leveradressen 
where land=1 
group by postkode, gemeente
order by postkode asc