0
我有一個要求,需要查詢每個類型的前5個新聞並返回到前端,由JPA實現。postgreSQL分類限制
我現在已經兩種解決方案,
- 一是通過註釋來手動添加聯合SQL,
- 呼叫通過循環不同參數類型的服務。
其實我要的是就像SQL如下
select id, title, content
from portal p
where p.type = 'NEWS'
order by create_date
limit 5
union
select id,title,content,
from portal p
where p.type = 'MAG'
order by create_date
limit 5
union...
解決方案,需要對代碼JAVA許多SQL語句,而溶液B是不是有效,因爲類型超過10
有沒有其他的方式來查詢數據?通過註釋或PostgreSQL函數?我是JPA & Postgres的新手。
在此先感謝。
是的......我忘了分區。謝謝 :) –