Follow these steps until the issue is resolved
  1. Make the query static instead of dynamic
  2. Recreate the query
  3. Break the large query into smaller groups and do the export twice