Cannot build correctly
Integer indicatedAmount = 2; String sql = "SELECT customer_id, count(id) as count_of_orders from orders group by customer_id"; You need something like:
String sql = "SELECT customer_id, count(id) AS count_of_orders FROM orders WHERE count_of_orders > 2 GROUP BY customer_id";