Pergunta

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)
Foi útil?

Solução

I think you're just looking for HAVING:

select units, count(*)
from old_table
group by units
having count(*) > 2000

Outras dicas

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top