0

我正在尝试使用下面的代码选择除前 2000 行之外的所有行,但出现以下错误。

new_table = sqldf("select units, count(*)
                   from old_table
                   group by units
                   where count(*) > 2000")
Error in sqliteExecStatement(con, statement, bind.data) : 
  RS-DBI driver: (error in statement: near "where": syntax error)
4

2 回答 2

5

我想你只是在寻找HAVING

select units, count(*)
from old_table
group by units
having count(*) > 2000
于 2013-07-12T17:34:26.977 回答
0

任何引用在当前查询中创建的值的 where 语句都需要嵌入到子查询中。

相反,您可以使用:

select * from 
(
select units, count(*) as count
from old_table
group by units
)
where count > 2000
于 2013-07-12T17:37:40.693 回答