SQL Server - GROUP BY on one column

后端 未结 5 1970
感情败类
感情败类 2020-12-31 04:48

I\'m trying to get orders from an orderview. In my view I do have some rows with exactly the same values, but I want to group these values on orderid and take the sum of the

5条回答
  •  Happy的楠姐
    2020-12-31 05:30

    In your scenario it doesn't seem correct to group-by Order_id having varying Article_id. You expected result seems wrong. It should be:

    PR10.001 has two Article_id 20.001a, 41.022b and total quantity 4 (not 3)

    Is your expectation is to get total quantity for each Order_id but retaining varying column too then you need to decide on expected result? something like:

     Order_id   Customer_id   Article_id            Delivery_date   Quantity
     ---------------------------------------------------------------------------
     PR10.001   11            20.001a, 41.022b      17-04-2013      4
     PR13.001   15            41.022b               19-04-2013      2
    

提交回复
热议问题