我想将 Sid = 1 的所有 LineAmount 相加,如何在 SQLite 中执行?
SQL语句需要做什么?
await db.QueryAsync<Transaction>("Select * From Transaction Where Sid =1");
class TransactionLine
{
[PrimaryKey, AutoIncrement]
public int TId { get; set; }
public int Sid { get; set; }
public string No { get; set; }
public string Description { get; set; }
public decimal Quantity { get; set; }
public decimal UnitPrice { get; set; }
public decimal LineDisPerc { get; set; }
public decimal LineDiscAmt { get; set; }
public decimal LineAmount { get; set; }
public decimal FinalAmount { get; set; }
}
- - 更新:
using (var db = new SQLite.SQLiteConnection(DBPath))
{
var Orders = db.Query<TransactionLine>("Select *, Sum(FinalAmount) From TransactionLine where Sid ==" + OrderId);
foreach (var lineTrans in Orders)
{
txtBlkAMT.Text = lineTrans.Amount.ToString();
}
}
问题:
- 如果我有 3 行订单,则总结不正确。
----- 更新 2。
这有效:
但是在 SQL 语句中使用 Sum() 或其他函数有什么捷径吗?
十进制 LineTTL = 0; 十进制 LineAmt = 0; 整数计数=0;
var Orders = db.Query<TransactionLine>("Select * From TransactionLine where SId ==" + OrderId);
foreach (var lineTrans in Orders)
{
LineAmt = lineTrans.Amount;
LineTTL = LineTTL + LineAmt;
TTLAmt = LineTTL;
}