ID Title Qty
1 BMW 2
2 VW 3
我想在一个SQL查询中查找数量之和并将其除以当前数量。 例如:
SUM (Qty) = 5
,所以我想按公式计算分数。 2/5和3/5
ID title newscores
1 BMW 2/5
1 vW 2/5
答案 0 :(得分:3)
SELECT id
,title
,qty/(select sum(qty) from cars)
FROM cars
GROUP BY id
答案 1 :(得分:0)
这应该有效
select title , sum (QTY) , t2.total, sum(QTY) / t2.total
from table , (select sum(QTY) as total from table) as t2
group by title
答案 2 :(得分:0)
答案 3 :(得分:0)
SELECT ID, Title, CONCAT( Qty, '/', (SELECT SUM( Qty) FROM table1) ) AS 'newscores'
FROM `table1`