2013-04-09 115 views
1

我困在Mysql查詢中,甚至不知道它是否可能。組表第一列第一列和第二列lastRow

我有以下表

enter image description here

我想pstatus集團在startdnt列包含第一行值和enddnt包含組的最後行值的方式。最終的結果是這樣的

enter image description here

所以與此查詢我能得到以下結果

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

enter image description here

請注意pstatus(b)可重複n次數。 在此先感謝..

+0

哪些是你真正需要的:從第一個和最後一個行或最大和最小日期的日期? – 2013-04-09 20:38:57

+0

你是否需要僅加入具有相同enddnt和startdnt的行?可能會有一些重疊的時間間隔? – fthiella 2013-04-09 20:55:14

+0

@ G-Nugget你是對的第一行日期是最後一行dat是最​​大 – 2013-04-10 05:12:52

回答

0

如何:

SELECT pstatus,min(startdnt) as StartDate,max(enddnt) as EndDate ... 
相關問題