gpt4 book ai didi

sql - 如何在SQL中计算多行

转载 作者:行者123 更新时间:2023-12-02 05:17:38 24 4
gpt4 key购买 nike

我有一个看起来像这样的表格:

ComputerID | Free_Space | Disk_Size
------------------------------------------
Computer1 | 10 | 15
Computer1 | 10 | 10
Computer1 | 05 | 10
Computer2 | 05 | 05
Computer2 | 05 | 10
Computer3 | 11 | 15
Computer3 | 04 | 05

我需要实现这样的目标:

ComputerID | Free_Space | Disk_Size
------------------------------------------
Computer1 | 25 | 35
Computer2 | 10 | 15
Computer3 | 15 | 20

我尝试过类似的方法,但没有成功。

 SELECT ComputerID,
SUM(free_space/1000000000) AS 'Total Free Space',
SUM(disk_size/1000000000) AS 'Total Size'
FROM myTable
ORDER BY ComputerID

任何帮助将不胜感激。

最佳答案

SELECT ComputerID,
SUM(free_space/1000000000) AS 'Total Free Space',
SUM(disk_size/1000000000) AS 'Total Size'
FROM myTable
GROUP BY ComputerID

关于sql - 如何在SQL中计算多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9005869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com