0

Esta consulta me funciona bien en mysql pero quiero pasarlo a la forma CodeIgniter , models, me pueden ayudar con esto:

SELECT registro.*,CONCAT(usuarios.apellidos,', ',usuarios.nombres) as appnom FROM (SELECT *, bingo+chancho+pollada as total FROM (SELECT idusuario, sum(pagado) as bingo, sum('') as chancho, sum('') as pollada, 1 as tarjeta FROM tbingo b WHERE pagado=1 GROUP BY idusuario
union all
SELECT idusuario,  sum('') as bingo, sum(pagado) as chancho, sum('') as pollada, 2 as tarjeta FROM tchancho c WHERE pagado=1 GROUP BY idusuario
union all
SELECT idusuario,  sum('') as bingo, sum('') as chancho, sum(pagado) as pollada, 3 as tarjeta FROM tpollada  p WHERE pagado=1  GROUP BY idusuario) as tabla  
GROUP BY idusuario) as registro join usuarios  ON registro.idusuario=usuarios.id

1 respuesta 1

1

ya encontré la respuesta tanto buscar y buscar ...

class Cobradores_model extends CI_Model {

    public function getCobradores(){
        $query = $this->db->query("SELECT registro.*,CONCAT(usuarios.apellidos,', ',usuarios.nombres) as appnom FROM (SELECT *, bingo+chancho+pollada as total FROM (SELECT idusuario, sum(pagado) as bingo, sum('') as chancho, sum('') as pollada, 1 as tarjeta FROM tbingo b WHERE pagado=1 GROUP BY idusuario
        union all
        SELECT idusuario,  sum('') as bingo, sum(pagado) as chancho, sum('') as pollada, 2 as tarjeta FROM tchancho c WHERE pagado=1 GROUP BY idusuario
        union all
        SELECT idusuario,  sum('') as bingo, sum('') as chancho, sum(pagado) as pollada, 3 as tarjeta FROM tpollada  p WHERE pagado=1  GROUP BY idusuario) as tabla  
        GROUP BY idusuario) as registro join usuarios  ON registro.idusuario=usuarios.id");
        return $query->result();
    }
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.