我在MariaDB中有以下查询
MariaDB [nova]> SELECT hostname, instances.created_at,
SUM(TIMESTAMPDIFF(hour,instances.created_at, NOW())) AS 'Total Hours',
JSON_EXTRACT(flavor, '$.cur."nova_object.data".name') AS FLAVOR
FROM instances
JOIN instance_extra ON instances.uuid = instance_extra.instance_uuid
WHERE (vm_state='active' OR vm_state='stopped')
AND hostname LIKE '%bfbxp%'
Group by FLAVOR;
+------------------+---------------------+-------------+----------------+
| hostname | created_at | Total Hours | FLAVOR |
+------------------+---------------------+-------------+----------------+
| www5 | 2022-11-17 15:44:32 | 14703 | "gen.medium" |
| www6 | 2022-11-17 15:44:26 | 3678 | "gen.large" |
| www7 | 2022-11-17 15:44:46 | 7350 | "sriov.medium" |
+------------------+---------------------+-------------+----------------+
3 rows in set, 1 warning (0.007 sec)
我想应用每小时成本计算Total Hour * Cost
和以下成本,我为每个风味。我如何应用SQL查询,或者我应该使用脚本,如Python或bash做复杂的查询?"gen.medium"
成本$0.050
成本3578*0.50
"gen.large"
成本$0.060
成本14703*0.60
"sriov.medium"
成本$0.070
成本也是7350*0.70
我在想我可以创建#temp表,在表中添加每种口味的成本,然后连接两个表并运行计算。听起来容易吗?
1条答案
按热度按时间wfsdck301#
如果2024年成本将发生变化,你想更新你的应用程序而不是数据吗?-乔治·里希特
x一个一个一个一个x一个一个二个x