0

I'm trying to select all but the first 2000 rows using the code below, but I get the following error.

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)
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418

2 Answers2

5

I think you're just looking for HAVING:

select units, count(*)
from old_table
group by units
having count(*) > 2000
sgeddes
  • 62,311
  • 6
  • 61
  • 83
0

Any where statement that references a value created in the current query needs to be embedded in a subquery.

Instead, you could use:

select * from 
(
select units, count(*) as count
from old_table
group by units
)
where count > 2000
canary_in_the_data_mine
  • 2,193
  • 2
  • 24
  • 28