想請教大家一下我有兩張透過select產生的表,分別如下
表1:
SELECT processors.device_id,ROUND(AVG(processor_usage),2) FROM processors GROUP BY processors.device_id
表2:
select
devices.device_id,devices.hostname,devices.sysName,mempools.mempool_descr,mempools.mempool_perc,storage.storage_descr,storage.storage_perc
from devices INNER JOIN mempools ON devices.device_id=mempools.device_id INNER JOIN storage ON devices.device_id=storage.device_id
WHERE (mempools.mempool_descr='Physical memory' OR mempools.mempool_descr='Real Memory') AND (storage.storage_descr = '/' OR storage.storage_descr = 'C:')
想問一下要怎麼下SQL語法才能產生類似下面這張透過device_id合併過後表,試了很久都不行,請前輩幫幫忙 感謝!!
SELECT * FROM (表1 SQL) AS TableA
LEFT JOIN (表2 SQL) AS TableB ON TableB.device_id=TableA.device_id
LEFT JOIN 或 INNER JOIN
大概寫法如下
select
devices.device_id,devices.hostname,devices.sysName,mempools.mempool_descr,mempools.mempool_perc,storage.storage_descr,storage.storage_perc,ROUND(AVG(processor_usage),2)
from devices
INNER JOIN mempools ON devices.device_id=mempools.device_id
INNER JOIN storage ON devices.device_id=storage.device_id
join processors on devices.device_id==processors.device_id
WHERE (mempools.mempool_descr='Physical memory' OR
mempools.mempool_descr='Real Memory') AND (storage.storage_descr = '/' OR storage.storage_descr = 'C:')
group by devices.device_id,devices.hostname,devices.sysName,mempools.mempool_descr,mempools.mempool_perc,storage.storage_descr,storage.storage_perc