2017-08-26 61 views
-2

我有一個SQL表包含記錄如下,我想通過查詢 組針對較小的金額不存在針對每個PropertyID和TenantID。 例如:我想對-2500 1個物業ID 2. TenantIDSQL - 通過查詢定製組

PropertyID TenantID Amount 
1    2  -6000 
1    2  -2500 
3    3  -15000 
3    3  -10000  

預計產量低於

PropertyID TenantID Amount 
1    2  -2500 
3    3  -10000 
+1

HTTPS://meta.stackoverflow。 com/questions/271055/tips-for-asking-a-good-structured-query-language-sql-question/271056 – Serg

+0

你能更好地解釋你需要什麼嗎? – nicolascolman

+0

後期修改爲預期輸出 –

回答

0

是這樣的:

Select PropertyId, TenantID, min(Amount) 
From YourTable 
Group by PropertyId, TenantID