title: MonetDB: How to count in last N rows?
body: <p>This one is not working</p>
  
  <p><code>select count(*) from table where col = 'value' order by id desc limit 100</code></p>
  
  <p>Error: <code>identifier 'id' unknown</code></p>
  
  <p>This also not working</p>
  
  <p><code>select count(*) from (select * from table order by id desc limit 100) as temp where col = 'value'</code></p>
  
  <p>Error: <code>syntax error, unexpected ORDER, expecting UNION or EXCEPT or INTERSECT or ')'</code></p>
  
  <p>Same if I will use <code>offset ...</code> instead of <code>order by ... desc limit ...</code> - <code>syntax error, unexpected OFFSET</code></p>
  
  <p>The only one way I found is to get count of all rows in table and</p>
  
  <p><code>select count(*) from (select ROW_NUMBER() over () as n, table.* from table) as temp where n &gt; %COUNT% - 100 and col = 'value'</code></p>
  
  <p>Is there better way to do count in N last rows?</p>