我有两个我想加入的精选语句。另外,它们工作正常,mysql告诉我我有语法错误,我不知道在哪里。
查询1是:
select * from(
select items.hostid, trends_uint.itemid,
avg(trends_uint.`value_avg`)/1024/1024/1024 as Average_Used, clock,
date_format(from_unixtime(trends_uint.`clock`), '%Y-%m') AS report_date from trends_uint, items
where (trends_uint.itemid = 75283 and items.hostid=10222)
group by trends_uint.itemid, report_date)
as used;
+
| hostid | itemid | Average_Used | clock | report_date |
+
| 10222 | 75283 | 1764.8172729810664676 | 1403344800 | 2014-06 |
| 10222 | 75283 | 1792.1519809950560109 | 1404190800 | 2014-07 |
+
查询2是:
select * from (select items.hostid, trends_uint.itemid,
avg(trends_uint.`value_avg`)/1024/1024/1024 as Space_Allocated, clock,
date_format(from_unixtime(trends_uint.`clock`), '%Y-%m') AS report_date from trends_uint, items
where (trends_uint.itemid = 75281 and items.hostid=10222)
group by trends_uint.itemid, report_date) as allocated;
+
| hostid | itemid | Space_Allocated | clock | report_date |
+
| 10222 | 75281 | 2432.0000000000000000 | 1403344800 | 2014-06 |
| 10222 | 75281 | 2432.0000000000000000 | 1404190800 | 2014-07 |
+
我尝试以以下身份加入:
select * from(
select items.hostid, trends_uint.itemid,
avg(trends_uint.`value_avg`)/1024/1024/1024 as Average_Used, clock,
date_format(from_unixtime(trends_uint.`clock`), '%Y-%m') AS report_date from trends_uint, items
where (trends_uint.itemid = 75283 and items.hostid=10222)
group by trends_uint.itemid, report_date)
as used
join
select * from (select items.hostid, trends_uint.itemid,
avg(trends_uint.`value_avg`)/1024/1024/1024 as Space_Allocated, clock,
date_format(from_unixtime(trends_uint.`clock`), '%Y-%m') AS report_date from trends_uint, items
where (trends_uint.itemid = 75281 and items.hostid=10222)
group by trends_uint.itemid, report_date) as allocated
on allocated.report_date=used.report_date;