简体   繁体   English

像mysql结构一样的数据透视表

[英]Pivot table like mysql structure

Need some help with a mySQL statement. 需要一些有关mySQL语句的帮助。 I currently have the following data which captures every change in delivery dates of different orders (with order number): 我目前拥有以下数据,这些数据捕获了不同订单(带有订单编号)的交货日期的每一次更改:

Order number    Delivery date

VO15010228-1    2015-06-11
VO15010228-1    2015-05-10
VO15010969-1    2015-06-25 
VO15010969-1    2015-05-25

I need to display this into a table like this: 我需要将其显示在这样的表中:

Order number    Current del. date     Previous del. date
VO15010228-1    2015-06-11            2015-05-10
VO15010969-1    2015-06-25            2015-05-25

I tried group_concat in my SQL statement, but I can't work with multiple dates into one single value. 我在SQL语句中尝试了group_concat,但无法将多个日期合并为一个值。 Any ideas? 有任何想法吗?

Kind regards, 亲切的问候,

You can use the following query: 您可以使用以下查询:

SELECT OrderNumber, MAX(DeliveryDate) AS Current, MIN(DeliveryDate) AS Previous
FROM mytable
GROUP BY OrderNumber

It will work for a simple scenario like the one of your sample data. 它适用于简单的场景,例如您的示例数据之一。

Demo here 在这里演示

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

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