I have a very extensive query when I try to insert in the database it does not work, I do not know why

0
$result = $db->query("
                SELECT RES.morada, RES.espaco, SUM(DATEDIFF(RES.data_fim, RES.data_inicio)*RES.tarifa) AS pago
                FROM (
                    SELECT A.morada AS morada, A.codigo AS espaco, A.data_inicio, O.data_fim, O.tarifa
                    FROM Aluga A, Espaco E, Oferta O, Estado ES
                    WHERE A.morada ='IST' AND A.morada = E.morada AND A.morada = O.morada AND A.codigo = E.codigo AND A.codigo = O.codigo AND A.data_inicio = O.data_inicio AND A.numero = ES.numero AND ES.estado = 'Paga'
                    UNION
                    SELECT P.morada AS morada, P.codigo_espaço AS espaco, A.data_inicio, O.data_fim, O.tarifa
                    FROM Aluga A, Posto P, Oferta O, Estado ES
                    WHERE A.morada ='IST' AND A.morada = P.morada AND A.morada = O.morada AND A.codigo = P.codigo AND A.codigo = O.codigo AND A.data_inicio = O.data_inicio AND A.numero = ES.numero AND ES.estado = 'Paga'
                    ) AS RES
                GROUP BY RES.morada, RES.espaco;
    
asked by anonymous 01.12.2016 / 22:38

0 answers