我正在尝试使用下面的代码选择除前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)
答案 0 :(得分:5)
我认为你只是在寻找HAVING
:
select units, count(*)
from old_table
group by units
having count(*) > 2000
答案 1 :(得分:0)
任何引用当前查询中创建的值的where语句都需要嵌入子查询中。
相反,您可以使用:
select * from
(
select units, count(*) as count
from old_table
group by units
)
where count > 2000