Count rows by sql.