Construye la consulta SQL

def result(self, *args, **kwargs):
        """
        Construye la consulta SQL
        """
        prettify = kwargs.get('pretty', False)
        self.__prepareData__()
        sql = 'SELECT '
        sql +=  ', '.join(self.fields)
        
        if len(self.tables) > 0:
            if prettify:
                sql += '\n'
            else:
                sql += ' '
            sql +=  'FROM '
            sql +=  ', '.join(self.tables)
        if self.where_criteria.size() > 0:
            if prettify:
                sql += '\n'
            else:
                sql += ' '
            sql +=  'WHERE '
            sql +=  self.where_criteria.result()
        if len(self.group_fields) > 0:
            if prettify:
                sql += '\n'
            else:
                sql += ' '
            sql +=  'GROUP BY '
            sql +=  ', '.join(self.group_fields)
        if len(self.order_by_fields) > 0:
            if prettify:
                sql += '\n'
            else:
                sql += ' '
            sql +=  'ORDER BY '
            sql +=  ', '.join(self.order_by_fields)
            if prettify:
                sql += '\n'
            else:
                sql += ' '

        return sql