gpt4 book ai didi

sql - Select * from table with where and order by clause 问题

转载 作者:太空宇宙 更新时间:2023-11-03 11:19:25 25 4
gpt4 key购买 nike

我需要获取有评论的项目数,但我无法让这条 SQL 语句为我工作........有什么建议吗?

Select count(Name) as TotalComments 
from TableName where comment <> ''
order by ID

错误信息:

Column "TableName.ID" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

我到底错过了什么?

最佳答案

等一下...

Select count(Name) as TotalComments  
from TableName where comment <> ''
order by ID

您正在选择计数,因此 Order By 子句毫无意义。你应该得到一个标量结果。 (单个值,而不是行集合)

这是一个技巧问题吗?现在还为时过早。

只需删除“Order By”子句。这是不必要的。

关于sql - Select * from table with where and order by clause 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301583/

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