gpt4 book ai didi

sql选择5个最高值

转载 作者:行者123 更新时间:2023-12-02 06:56:19 25 4
gpt4 key购买 nike

我正在尝试选择具有最高 count 值的 5 行

这是我的查询:

string sql = "SELECT   top 5  count FROM  Likes  ORDER BY COUNT(*) DESC";

它只是抛出一个错误代码

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

这是我明天要展示的项目... enter image description here

最佳答案

在 SQL Server 上,只需执行以下操作:

 SELECT TOP 5 * FROM Likes ORDER BY [Count] DESC

这假设您的 Likes-table 已经包含一个名为 [Count] 的列,这意味着您不需要自己计算记录(这就是 COUNT(*) 会)。

关于sql选择5个最高值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30727773/

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