我提供了一個我的數據外觀示例。餐桌上充滿了客房餘量不足的情況。每天都會生成一份報告,並帶有負餘額。報告使用新的reportdate導入到我的表格中。有沒有一種方法可以實現以下目標:每天重複清理數據
返回customerID達到找到的最大ending_amount的第一個日期的行。這意味着如果customerid在20天的數據第10天達到-3.50的ending_amount,我希望它在20天的第10天只返回一行數據,而忽略與該customerid相關的其他19天的數據。
注:
** - **客戶ID是一個獨特的價值。
** - **當起始金額爲<> ending_amount時,表示該帳戶餘額發生了變化。
是否有無論如何,我可以通過清理這張表,如何或通過編寫查詢來實現我的目標?
謝謝你的幫助。
Expected Data output
reportdate customerid starting_amount ending_amount
1/1/17 2 -0.00 -0.50
1/3/17 3 -0.50 -1.00
1/4/17 1 -0.50 -3.27
1/4/17 4 -0.00 -0.50
1/4/17 5 -0.50 -1.32
的樣本數據
tbl_accountchange
reportdate customerid starting_amount ending_amount
1/1/17 1 -0.00 -0.50
1/1/17 2 -0.00 -0.50
1/2/17 1 -0.50 -0.50
1/2/17 2 -0.50 -0.50
1/2/17 3 -0.00 -0.50
1/3/17 1 -0.50 -0.50
1/3/17 2 -0.50 -0.50
1/3/17 3 -0.50 -1.00
1/3/17 4 -0.00 -0.50
1/3/17 5 -0.00 -0.50
1/4/17 1 -0.50 -3.27
1/4/17 2 -0.50 -0.50
1/4/17 3 -1.00 -1.00
1/4/17 4 -0.50 -0.50
1/4/17 5 -0.50 -1.32
因此,在您的數據示例中,預期的輸出是什麼? –
你好,我已經添加了我的期望輸出。基本上,我想返回第一個reportdate上的每一行,該帳戶達到了表中找到的最大結餘餘額。客戶ID不應該多於一次返回。 –