有没有办法在SQL中同时选择列和其他列的总和?
示例:
SELECT sum(a) as car,b,c FROM toys
答案 0 :(得分:1)
尝试添加GROUP BY
SELECT sum(a) as car,b,c FROM toys
GROUP BY b, c
答案 1 :(得分:1)
怎么样:
select sum(a) over(), b, c from toy;
或者,如果需要:
select sum(a) over(partition by b), b, c from toy;
答案 2 :(得分:0)
SELECT b,
c,
(SELECT sum(a) FROM toys) as 'car'
FROM toys
答案 3 :(得分:0)
由于您没有提供太多上下文,我认为您的意思是以下之一:
SELECT (SELECT SUM(a) FROM Toys) as 'car', b, c FROM Toys;
或
SELECT SUM(a) as Car, b, c FROM Toys GROUP BY b, c;