Mysql
 sql >> Database >  >> RDS >> Mysql

Perché questa query non funziona in SQLite ma funziona bene in MySQL e MSAccess?

In SQLite, ottieni una colonna a incremento automatico utilizzando INTEGER PRIMARY KEY .(E se fai affidamento sui valori effettivi di payers.id nella query, dovresti fornirli in modo esplicito.)

Non dovresti provare a nidificare i join quando non è necessario:

SELECT payer_payment.payer_id,
       Sum(payer_payment.amount)                             AS total_paid,
       Sum(payer_payment.pays * payments_share.single_share) AS fair_share
FROM       payers
INNER JOIN payer_payment
        ON payers.id = payer_payment.payer_id
INNER JOIN (SELECT payment_id,
                   Sum(amount) / Sum(pays) AS single_share
            FROM   payer_payment
            GROUP  BY payment_id) AS payments_share
        ON payer_payment.payment_id = payments_share.payment_id
WHERE payers.user_id = 1
GROUP BY payer_payment.payer_id;

SQLFiddle