我有一个名为api_keys
的表,我跟踪api事务。我一直给提供商apiA
提供3个api密钥,每个密钥允许最多5000个呼叫。我可以运行单独的查询来获取total number of calls
,api keys with < 5000 calls
和api keys with 5000 calls
。但是,如何将这些查询放入显示consumed
和not_used
百分比的查询中? SQLFIDDLE
所需的输出百分比:
+----------+----------+
| Consumed | Not_used |
+----------+----------+
| 70 | 30 |
+----------+----------+
api通话总数
SELECT COUNT(*) * 5000 as total_api_calls FROM api_keys WHERE `source` = 'apiA';
未达到5000次通话的Api键:
SELECT * FROM api_keys WHERE `source` = 'apiA' and `transactions` < 5000
已达到5000次通话的Api键:
SELECT * FROM api_keys WHERE `source` = 'apiA' and `transactions` >= 5000;