Abstract: This disclosure proposes systems, methods, and apparatus that identify raw SQL queries that are likely to cause a double counting error, and if such a SQL query is identified, then convert the raw SQL query into SQL queries that account for and avoid double counting. In some embodiments, this process uses queries and subqueries that refer back to a common table expression (CTE) in order to reduce code length and increase query execution speed.