Home > Mobile >  Merge several rows in SQL
Merge several rows in SQL

Time:11-26

I am trying to merge several rows with the same "OrderNumber". An order have several rows with different data records. Each time step is saved in one record, as you can see in the image below. enter image description here

Now I would like to summarize the time information for the respective "OrderNumber"s. So it should look like this:

enter image description here

I was wondering how to make this with an SQL query..

CodePudding user response:

Use GROUP BY with following query:

SELECT
  OrderNumber,
  MAX(DateOfReceipt),
  MAX(ShippingDate),
  MAX(ControlDate),
  MAX(DeliveryDate)
FROM
  Table
GROUP BY
  OrderNumber
  • Related