简体   繁体   中英

how to join correlated subquery with outer table?

I have a query like this -

UPDATE ACTION a 
INNER JOIN subscriberinfo s ON a.subscriberId = s.id AND a.subscriberId=118  
INNER JOIN ticket t ON t.subscriberId = s.id AND s.id=118 
SET a.exceedusage = (SELECT FORMAT(((SUM(dataVolumeDownLink + dataVolumeUpLink))/1048576),2) 
                    FROM cdr c 
                    WHERE c.msisdn =12424474969 
                    AND c.msisdn = s.msisdn
                    AND c.eventDate>t.cdrEventDate 
                    AND c.eventDate < a.actionTakenOn) 
WHERE a.remark='Reason : Data limit crossed' 
AND a.exceedusage IS NULL;

I want to update action tables column, am I doing something wrong in this query?

Please explain me with an example that how to perform such kind of update,if possible.

Please, use group by where aggregate function is there:

  UPDATE ACTION a 
    INNER JOIN subscriberinfo s ON a.subscriberId=118  
    INNER JOIN ticket t ON s.id=118 
    SET a.exceedusage = (SELECT FORMAT(((SUM(dataVolumeDownLink + dataVolumeUpLink))/1048576),2) 
                        FROM cdr c 
                        WHERE c.msisdn =12424474969 
                        AND c.eventDate>t.cdrEventDate 
                        AND c.eventDate < a.actionTakenOn group by c.msisdn ) 
    WHERE a.remark='Reason : Data limit crossed' 
    AND a.exceedusage IS NULL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM