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

Fejl SQL-forespørgsel:Brug SUM-metoden, når #1054 - Ukendt kolonne 'tbl_customers.id' i 'where clause'

Du brugte tbl_customers på underforespørgslen, hvor du ikke havde adgang til den. Du skulle bare deltage i stedet for at bruge hvor:

SELECT tbl_customers.*,(SELECT SUM(amount) As Amount
FROM 
(
    SELECT tcc.entry_fees*COUNT(tccc.match_contest_id) as amount 
    FROM `tbl_cricket_customer_contests` tccc 
    JOIN `tbl_customers` ON (tccc.customer_id = tbl_customers.id)
    LEFT JOIN tbl_cricket_contest_matches tccm on(tccm.id=tccc.match_contest_id) 
    LEFT JOIN tbl_cricket_contests tcc ON (tcc.id=tccm.contest_id) 
    GROUP BY tccc.match_contest_id
) As DT) as spendamount
FROM (`tbl_customers`) 
WHERE `tbl_customers`.`is_deleted` = 'N' 
GROUP BY `tbl_customers`.`id` 
ORDER BY `spendamount` DESC


  1. Løsning for MySQL begrænset TIMESTAMP-interval?

  2. Base64-kodning og afkodning i oracle

  3. Kan Hibernate arbejde med MySQL's ON DUPLICATE KEY UPDATE-syntaks?

  4. Sådan fungerer SQLite Avg()