简体   繁体   中英

group table with 1st Column of one Row and 2nd Column of lastRow

I am Stuck With Mysql Query and don't even know if it is possible or not.

I have the Following Table

在此处输入图片说明

And I want to Group pstatus in a way that startdnt column contains the first row value and enddnt contain the last row value of the group. Final result will look like this

在此处输入图片说明

so for with this query i'm able to obtain following results

SELECT pstatus,startdnt,enddnt,sum(Datediff(enddnt,startdnt)) as days  FROM status  GROUP by pstatus ORDER BY startdnt

在此处输入图片说明

Please note pstatus (b) may be repeat n number of times. Thanks in advance..

这个怎么样:

SELECT pstatus,min(startdnt) as StartDate,max(enddnt)  as EndDate ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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