SQL_Model: count() and sum() rewrite