Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何使用join连接两个表_Mysql - Fatal编程技术网

Mysql 如何使用join连接两个表

Mysql 如何使用join连接两个表,mysql,Mysql,有谁能帮我在一个表中连接两个查询吗 灯具详细信息表: select mac_id, round(sum(luminary_count::int * wattage::int)::numeric/100, 2) as rated_power from luminary_details AS A join geo_light as gl on A.mac_id = gl.id group by A.mac_id //最后更新 select mac_id,

有谁能帮我在一个表中连接两个查询吗

灯具详细信息表:

select 
    mac_id, round(sum(luminary_count::int * wattage::int)::numeric/100, 2) as rated_power 
from 
    luminary_details AS A
join 
    geo_light as gl on A.mac_id = gl.id 
group by
    A.mac_id
//最后更新

select mac_id, (tactivep::numeric)
from lastupdated_all AS A
join geo_light as gl on A.mac_id = gl.id 
group by A.mac_id

您可以使用geo_ligth作为主表,并将2查询作为subselect左连接。。通过id连接=mac\U id

select gl.id,  t1.rated_power, t2.tactivep
from  geo_light  gl
LEFT JOIN  (
  select mac_id, round(sum(luminary_count::int * wattage::int)::numeric/100, 2) as rated_power 
  from luminary_details AS A
  join geo_light as gl on A.mac_id = gl.id 
  GROUP BY A.mac_id
)  t1 on t1.mac_id  = gl.id 
LEFT JOIN  (
  select mac_id, (tactivep::numeric) num_tactivep
  from lastupdated_all AS A
  join geo_light as gl on A.mac_id = gl.id 
  GROUP BY A.mac_id
) t2 on t2.mac_id = gl.id 

::int-不是mysql快捷方式?所以您想加入这两个查询?您使用的是Postgres还是mysql?也许您想在这里查询工会。是………..^--对哪个问题是?