我试着在我的选择查询中对数量字段求和(按日期值对它们进行分组,但是Sql继续给我错误,说明不是列在我的GroupBy中分组,但我只想按日期对它们进行分组
这是我的疑问:
SELECT Date, Clave_PDV, Che, Lin, Dish, Dish_Name, Type,
sum(Quantity) as Quant, Price, Total, Tur, Tur_Name, Group,
Group_Name, Pdv_Name, St_Pla, St_Che
FROM Dish_Sales
GROUP BY Date
如何按日期对数量进行求和(数量)?
答案 0 :(得分:2)
您将删除所有不想要的列:
SELECT Date, sum(Quantity) as Quant
FROM Dish_Sales
GROUP BY Date;
答案 1 :(得分:1)
如果你想要按日期求和,你应该我们
SELECT Date, sum(Quantity) as Quant
FROM Dish_Sales
GROUP BY Date
否则,您应该对所有未聚合的列使用group by
SELECT Date, Clave_PDV, Che, Lin, Dish, Dish_Name, Type,
sum(Quantity) as Quant, Price, Total, Tur, Tur_Name, Group,
Group_Name, Pdv_Name, St_Pla, St_Che
FROM Dish_Sales
GROUP BY Date, Clave_PDV, Che, Lin, Dish, Dish_Name, Type,
Price, Total, Tur, Tur_Name, Group,
Group_Name, Pdv_Name, St_Pla, St_Che