简体   繁体   English

如何在mysql中合并相同值的行

[英]how to merge same value rows in mysql

I have a table that looks somewhat like this: 我有一张看起来像这样的表:

Table:Orders 表格:订单

OrderID  ProductID   Quantity   StoreID   OrderDate
01       1           5          1         05-10-2014
02       2           2          4         05-10-2014
03       1           1          3         05-10-2014
04       3           1          3         05-10-2014

Now i want to retrieve from above table "orders" data looks like this : 现在,我想从上面的表中检索“订单”数据,如下所示:

Retrieve Result 检索结果

ProductID       Quantity   StoreID    OrderDate 
(Product Merge) (SUM)      (COUNT)    (Date*)
1               6          2          05-10-2014
2               2          1          05-10-2014
3               1          1          05-10-2014

As per above "retrieve result" i want to merge my table "orders" data with ProductID 按照上面的“检索结果”,我想将我的表“订单”数据与ProductID合并

Thanks in advance 提前致谢

If I understood you correctly, you need GROUP BY . 如果我对您的理解正确,则需要GROUP BY You group them by the productID and select the sum of the quantities 您将它们按productID分组,然后选择数量的总和

SELECT SUM(Quantity), COUNT(StoreID), ... FROM Orders GROUP BY ProductID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM