在单个查询中,是否可以在一个表中对一堆值求和,并将其除以另一个表中的行数?两个表中都有一个共同的ID /密钥......
答案 0 :(得分:2)
仅供参考,您可以获得问题中提供的最少信息的积分。答案是可能的......这是伪造的代码,因为我猜你的表和列
select summing / counting as whynot
from
(select id, sum(whatever) as summing from where_ever ) a
inner join
(select id, count(1) as counting from what_ever)b
on a.id = b.id
where question = 'vague'
group by a.id
答案 1 :(得分:1)
select (select sum(x) from table1 where ...) / (select count(*) from table2 where ...)
答案 2 :(得分:-2)
如果不了解您的具体情况,如果您在另一个行中的行数不变(10),您可以执行类似的操作:
SELECT SUM(columnName)/10 FROM tableName