简体   繁体   中英

MySQL using current results for subquery. Correlated subquery?

I have a table that contains the following fields system_id partner_id uptime

I'm trying to get output that shows: system_id, uptime, partner_id, partner_uptime

So for every row that comes back from an initial select all I need to check if the partner id is in the table and retrieve it's uptime value. It's simple enough to do in excel but with 2M+ records it could take a while!

Can someone please help construct a basic query for this?

Thanks

You can use simple self join query here, assuming partner_id references to system_id :

select t.system_id, t.uptime, t1.partner_id, t1.uptime as partner_uptime
from table t join table t1 on t.system_id = t2.partner_id
where //your condition

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