Getting a query to work on SQLite as well as on MySQL
SELECT * FROM 
  (SELECT 
  discounts.*, 
  (SELECT COUNT(id) 
   FROM payments 
   WHERE payments.discount_id = discounts.id 
   GROUP BY payments.discount_id) AS usage_count
FROM discounts   
WHERE rate &gt; 10) table1 
WHERE usage_count &gt; 1