I'm guessing this is not possible without defining a function. The idea is that you have a table like
我猜这没有定义一个函数是不可能的。这个想法就是你有一张像这样的桌子
table:
----------------
| A | B | Total|
|---|---|------|
| 1 | 2 | 3 |
| 4 | 5 | 9 |
| 6 | 7 | 13 |
----------------
select */Total from table
----------------------------
| A | B | Total |
|-------|-------|----------|
| 0.333 | 0.667 | 1.00 |
| 0.8 | 0.556 | 1.00 |
| 0.462 | 0.538 | 1.00 |
----------------------------
select */(select max(*) from table) from table
----------------------------
| A | B | Total |
|-------|-------|----------|
| 0.167 | 0.286 | 0.231 |
| 0.667 | 0.714 | 0.692 |
| 1.000 | 1.000 | 1.000 |
----------------------------
1 个解决方案
#1
0
So you want operators on your output. You can simply do this to get your first example:
所以你想要输出你的运算符。你可以简单地这样做来得到你的第一个例子:
SELECT A/total, B/total, (A+B)/total FROM `table`
You don't even need a 'total' column:
您甚至不需要“总计”列:
SELECT A/(A+B), B/(A+B), 1 as total FROM `table`
Second one, if you are trying to get the average, same logic applies.
第二,如果你想获得平均值,则应用相同的逻辑。
#1
0
So you want operators on your output. You can simply do this to get your first example:
所以你想要输出你的运算符。你可以简单地这样做来得到你的第一个例子:
SELECT A/total, B/total, (A+B)/total FROM `table`
You don't even need a 'total' column:
您甚至不需要“总计”列:
SELECT A/(A+B), B/(A+B), 1 as total FROM `table`
Second one, if you are trying to get the average, same logic applies.
第二,如果你想获得平均值,则应用相同的逻辑。