0

これが私のコードです:

SELECT Invoice_detail.Xtype, 
       Invoice_detail.Totallineprice
FROM Invoice_detail Invoice_detail
      INNER JOIN Invoice_head Invoice_head ON 
     (Invoice_head.idx = Invoice_detail.Xinvoicehead)
WHERE ( Invoice_detail.Totallineprice <> 0 )
       AND ( Invoice_head.xCurrency = 1 )
ORDER BY Invoice_detail.Xtype

どちらが返されますか:

301  -  50
291  -  56.25
291  -  75
70   -  (125)
70   -  50
70   -  75

このコードを合計して、結果がこのように見えるようにするにはどうすればよいですか?

301  -  50
291  -  131.25
70   -  0

ご協力いただきありがとうございます!

4

1 に答える 1

4

このクエリを試してください。Sum を使用して、GROUP BY を使用して最初の列 (Invoice_detail.Xtype) のグループの 2 番目の列 (Invoice_detail.Totallineprice) を合計します。

SELECT Invoice_detail.Xtype, 
       SUM(Invoice_detail.Totallineprice)
FROM Invoice_detail Invoice_detail
      INNER JOIN Invoice_head Invoice_head ON 
     (Invoice_head.idx = Invoice_detail.Xinvoicehead)
WHERE ( Invoice_detail.Totallineprice <> 0 )
       AND ( Invoice_head.xCurrency = 1 )
GROUP BY  Invoice_detail.Xtype
ORDER BY Invoice_detail.Xtype
于 2014-12-08T16:21:19.580 に答える