使用sqldf仅显示count(*)> 2000的行

0 sql r sqldf

我试图使用下面的代码选择除前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)
Run Code Online (Sandbox Code Playgroud)

sge*_*des 5

我想你只是在寻找HAVING:

select units, count(*)
from old_table
group by units
having count(*) > 2000
Run Code Online (Sandbox Code Playgroud)