我的表格结果包含以下字段:
id count
____________
1 3
2 2
3 2
我必须从该表中形成另一个表分数,该分数应如下所示
id my_score
_____________
1 1.0000
2 0.6667
3 0.6667
那是my_score = count / MAX(count)但如果我给查询为
create TEMPORARY TABLE(select id,(count/MAX(count)) AS my_score from result);
仅检索到第一行.
提前致谢.
最佳答案
SELECT
a.ID,a.count / b.total
FROM result as A
CROSS JOIN (SELECT MAX(Count) AS Total From Result) AS B
B仅返回一行,因此您想将表的笛卡尔乘积与其自身的总和相乘以获得最终值.