我想從表中獲取上個月的記錄。我曾嘗試:選擇計數,而計數大於postgres中的特定數字sql
SELECT count(*) as numberOfRows from Table where created_at > CURRENT_DATE - INTERVAL '1 months'
這是好的,但我想添加一些條件:
If numberOfRows >= 10, do nothing (numberOfRows can be 20, 30, ...)
else if numberOfRows < 10, select from this table until numberOfRows = 10 (last 2 months, 3 months, etc...).
我怎麼能這樣做? 感謝您的進步!
你或你不想要一個多月前的記錄嗎?這點我不清楚。 –
你的描述聽起來很沒用。爲什麼不直接返回'最大(count(*),10)'? –