我正在尝试按照我在x天内记录的所有价格将数据分组到表格中。我在使用SQL语句时遇到问题,这是我当前的声明
// get the total amount for each date
public static List<DateAmountList> GetTotalAmount()
{
List<DateAmountList> results = new List<DateAmountList>();
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath))
{
results = conn.Query<DateAmountList>("SELECT Date, SUM(Amount) AS 'Amount' FROM DateAmountList GROUP BY Date");
}
return results;
}
这是我的product_prices表;
SELECT *, GROUP_CONCAT(Price) AS Prices FROM product_prices GROUP BY Product,Day
我希望价格按照这一天在1个表格中分组
+---------+--------------+
| Product | Day | Price |
+---------+--------------+
| Phone| 1 | 100 |
| Speaker| 1 | 50 |
| Phone | 2 | 230 |
| Speaker| 2 | 80 |
+---------+--------------+
答案 0 :(得分:1)
您必须删除Day
子句中的GROUP BY
。另外,将*
替换为Product
:
SELECT
Product,
GROUP_CONCAT(Price) AS Prices
FROM product_prices
GROUP BY Product
答案 1 :(得分:1)
如果要从最低到最高选择价格,则应在group_concat语句中使用order by
:
SELECT Product,
GROUP_CONCAT(Price ORDER BY Price) AS Prices
FROM product_prices
GROUP BY Product