我有一个这样的表:

=================================
| month | bread | milk | butter |
=================================
| Jan16 | 2.00  | 1.30 | 1.50   |
| Feb16 | 2.05  | 1.29 | 1.52   |
| March | 2.03  | 1.31 | 1.51   |
=================================


我想知道与第一个月相比价格的变化如何。
我想得到类似的东西:

=================================
| month | bread | milk | butter |
=================================
| Jan16 | 1.00  | 1.00 | 1.0000 |
| Feb16 | 1.025 | 0.99 | 1.0133 |
| March | 1.015 | 1.01 | 1.0067 |
=================================


我如何查询类似的内容:

SELECT bread[i]/bread[0] AS vBread, milk[i]/bread[0] as vMilk, butter[i]/butter[0] as vButter FROM table

最佳答案

一月加入:

select a.month, a.bread/b.bread vBread, a.milk/b.milk vMilk, a.butter/b.butter vButter
from mytable a
join mytable b on b.month = 'Jan16';

关于mysql - MySQL表参数变化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35369936/

10-11 17:07