如何使用 Sql 查询填充 CollectionView 以及 Xamarin 中的 Distinct、Sum 和 Count ....

How to Populate CollectionView with Sql Query with combination of Distinct, Sum and Count .... in Xamarin

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>

请问我怎样才能做到这一点,同时使用不同的和求和

使用 GROUP BY 代替 DISTINCT

DISTINCT 用于 select 不同的元素,仅此而已。如果你想聚合(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"

参考

How to combine SELECT DISTINCT and SUM()

SQL query with distinct and sum