项目上嵌套结果集查询,查询的列表再根据每个id进行查询计算,嵌套的sql如下: SELECT SUM(IFNULL(t.out_rate,0)) totalOutRate, SUM(IF(IFNULL(t.pre_power,0)-IFNULL(t.power,0)<0,0,IFNULL(t.pre_power,0)-IFNULL(t.power,0))) totalPower FROM ( SELECT i.id id,i.`station_id` station_id,i.`out_rate…