make count behave like in SQL

also fixed count behavior according to limit and offset.
fixes #1458