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

时间:2013-07-12 17:29:40

标签: 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)

2 个答案:

答案 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