我有一台名为tripdetails:如何在mySql中添加列值?
表结构:
**trip no** **invoice no** **total balance**
111 1 500
111 2 800
我想补充这两种发票总余额 ...意味着500 + 800 = 1300 ... 。
我有一台名为tripdetails:如何在mySql中添加列值?
表结构:
**trip no** **invoice no** **total balance**
111 1 500
111 2 800
我想补充这两种发票总余额 ...意味着500 + 800 = 1300 ... 。
SELECT trip_no,SUM(total_balance) as total
FROM tripdetails
WHERE trip_no = 111
GROUP BY trip_no;
这应该这样做。它用trip_no 111选择两行,然后对它们进行分组并选择余额总和。
SELECT SUM(total_balance) as invoice_total FROM tripdetails
我们必须使用聚合函数做column.There的总和是一个预先定义的功能,这有助于获得所需的输出。
语法:
select sum(column_name) as alias
from table_name
看来你正在寻找SQL的'SUM'。 –
你想'总结'吗?你想添加的地方?在桌子上? –
是的,我想添加在表中.. –