2017-05-08 201 views
0

請使用此選擇查詢來幫助我。如何選擇每個月的每月最大日期行

enter image description here

我需要找到 正是這樣

enter image description here

+0

請仔細閱讀http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so當問一個問題/ 285557和接受的答案 –

+0

你正在使用哪個DBMS? Postgres的?甲骨文? –

回答

0

在內部查詢查找最大日期爲Scheduleid,然後使用該scheduleid和的maxDate找到其對應的特定記錄到使用內部連接的最大日期。如果有兩個記錄對應相同的最大日期,這也將起作用。它會給這兩個記錄。

嘗試此查詢: -

Select a.* 
from 
your_table_name a 
inner join 
(
Select Scheduleid, max(ScheduledDate) as max_date 
from 
your_table_name 
group by Scheduleid 
) b 
on a.Scheduleid=b.Scheduleid and a.ScheduledDate=b.max_date 
+0

在此工作 –

+0

@MahfuzurRahman如果這有助於您,請訪問此鏈接http://stackoverflow.com/help/someone-answers –