SQL 查詢示例
using (SQLiteConnection conn = new SQLiteConnection(con.dBasePath))
{
SalesRecords.ItemsSource = conn.Query<DATA_BINDING.PURCHASED_PRODUCTS>
("SELECT DISTINCT([soldProduct]), (SUM ([soldAmount])) FROM
[PURCHASED_PRODUCTS] "
"WHERE salesDate BETWEEN '" btnDateFrom.Date.ToString("dd MMM yy")
"' AND '" btnDateTo.Date.ToString("dd MMM yy") "'");
}]
.....XAMARIN 代碼......
<Label **Text="{Binding soldProduct}"** HorizontalOptions="Start" Margin="8,0,0,0" FontSize="14" FontAttributes="Bold" TextColor="White"></Label>
<Label **Text="{Binding soldAmount}"** TextColor="#2ABD8F" HorizontalOptions="CenterAndExpand" FontSize="22" HorizontalTextAlignment="Center" FontAttributes="Bold" VerticalOptions="CenterAndExpand"
LineBreakMode="TailTruncation" Margin="0,-11,0,0"></Label>
請問我怎樣才能使這成為可能,同時具有不同的和總和
uj5u.com熱心網友回復:
使用GROUP BY而不是DISTINCT.
DISTINCT用于選擇不同的元素,僅此而已。如果你想聚合(SUM)你需要使用的專案GROUP BY。
"SELECT soldProduct, (SUM ([soldAmount])) FROM [PURCHASED_PRODUCTS] "
"WHERE salesDate BETWEEN '" btnDateFrom.Date.ToString("dd MMM yy")
"' AND '" btnDateTo.Date.ToString("dd MMM yy") "'" "GROUP BY soldProduct"
參考
如何結合 SELECT DISTINCT 和 SUM()
具有 distinct 和 sum 的 SQL 查詢
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/424304.html
