我正在尝试查询以下但未执行
SELECT
MAX(time) as last_time,
column_A,
column_B
from
table_1
WHERE
column_c='foo'
回复时出现以下错误消息
错误:列“column_A”必须出现在GROUP BY子句中或者是 用于聚合函数
然而,它正确回复了以下查询
SELECT MAX(time) as last_time from table_1 WHERE column_c='foo'
我做错了什么?
答案 0 :(得分:1)
不在聚合函数中的所有列必须在group by中 如果聚合函数中有任何列,则为子句。
SELECT MAX(time) as last_time, column_A, column_B
FROM table_1 WHERE column_c='foo'
GROUP BY column_A, column_B
答案 1 :(得分:1)
在另一个答案的评论中,您说您只想要一个值:
SELECT
"time" as last_time,
column_A,
column_B
from table_1
WHERE column_c = 'foo'
order by "time" desc
limit 1