如何通过汇总发票的每一行来查找发票总价?

时间:2018-04-26 15:17:06

标签: sql sum

如何从包含多张发票的表格中获取每张发票的总价?例如,

enter image description here

2 个答案:

答案 0 :(得分:3)

你可以使用总和和组 例如,如果您需要为每个inv_number求和,您可以使用line_units和line_price之间的乘积之和,例如:

select t.inv_number, sum(t.line_units*t.line_price) as total
from (
 your select  ........... 
) t
group by t.inv_number

如果你的my_table是一个joi结果,你可以

# abs_cosine should be a Tensor of shape (m, m)
mask = torch.ones(abs_cosine.size()[0])
mask = 1 - mask.diag()
sim_vec = torch.nonzero((abs_cosine >= threshold)*mask)

# sim_vec is a tensor of shape (?, 2) where the first column is the row index and second is the column index

答案 1 :(得分:0)

SELECT 
    CUS_FNAME
    ,CUS_FNAME
    ,SUM(LINE_UNITS * LINE_PRICE) TOTALPRICE
FROM 
    dbo.Invoices
GROUP BY
    CUS_FNAME,CUS_LNAME

非常简单,只是使用了group by。希望这有帮助!