我希望能够从相同的区域、类型和操作系统中减去 ondemand 的保留数量,然后将剩余的数量乘以费率。
这是mysql数据的示例转储
| Zone | Type | Qty | OS | Reservation | Rate |
| zone1 | type1 | 12 | linux | ondemand | 0.24 |
| zone1 | type1 | 6 | linux | reserved | 0.056 |
| zone1 | type2 | 3 | linux | ondemand | 0.82 |
| zone2 | type1 | 5 | mswin | ondemand | 0.24 |
| zone2 | type1 | 2 | mswin | reserved | 0.056 |
| zone2 | type2 | 3 | linux | ondemand | 0.82 |
| zone3 | type1 | 4 | linux | ondemand | 0.24 |
| zone3 | type1 | 1 | linux | reserved | 0.056 |
结果将是
| Zone | Type | Qty | OS | Reservation | Rate | sum() |
| zone1 | type1 | 6 | linux | ondemand | 0.24 | 1.44 |
| zone1 | type1 | 6 | linux | reserved | 0.056 | 0.336 |
| zone1 | type2 | 3 | linux | ondemand | 0.82 | 0.246 |
| zone2 | type1 | 3 | mswin | ondemand | 0.24 | 0.72 |
| zone2 | type1 | 2 | mswin | reserved | 0.056 | 0.112 |
| zone2 | type2 | 3 | linux | ondemand | 0.82 | 0.246 |
| zone3 | type1 | 3 | linux | ondemand | 0.24 | 0.72 |
| zone3 | type1 | 1 | linux | reserved | 0.056 | 0.056 |
我不确定如何获得一个独特的声明来处理这个问题。我不知道这是否可以使用 mysql 或者我是否需要编写脚本然后生成输出。任何帮助表示赞赏。
对于包含按需的类型和操作系统,区域中并不总是有相应的保留。