【发布时间】:2018-10-30 10:50:05
【问题描述】:
我有一个存储过程,它构建一个临时表并在最后执行一个选择。只要我不包含 l.beskrivning ,它就可以正常工作,这是一个将国家代码映射到国家名称的表。该过程是有效的,但是当我测试它时,我收到以下错误:
列“LK.b”在选择列表中无效,因为它是 不包含在聚合函数或 GROUP BY 子句中。
SELECT TOP 100 tmp.BuyerID, tmp.BuyerNumber, tmp.BuyerName, tmp.BuyerAddress, tmp.BuyerCountryCode, l.b
FROM #tempGL AS tmp
INNER JOIN LK AS l ON l.land_id LIKE tmp.BuyerCountryCode
GROUP BY tmp.BuyerID, tmp.BuyerNumber, tmp.BuyerName, tmp.BuyerAddress, tmp.BuyerCountryCode
ORDER BY Count(*) DESC, tmp.BuyerName
我也尝试过完全删除 GROUP BY 和 ORDER BY 但我仍然遇到同样的错误。我在这里做错了什么?
【问题讨论】:
-
Select TOP *不是 MySQL 语法!使用您正在使用的正确 RDBMS 重新标记。
标签: sql sql-server group-by