user_id | sum | app_id | app_count
--------- ------ -------- -----------
1 | 100 | 3 | 1
2 | 300 | 2 | 1
4 | 1100 | 1 | 2
4 | 1100 | 4 | 1
我如何撰寫查詢,以便根據app_count的等級選擇不同的user_id?
這是我想要的結果:
user_id | sum | app_id | app_count
--------- ------ -------- -----------
1 | 100 | 3 | 1
2 | 300 | 2 | 1
4 | 1100 | 1 | 2
uj5u.com熱心網友回復:
在Postgres中,你將使用distinct on:
select distinct on(user_id)t.*
from t.
order by user_id, app_count desc。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/307985.html
標籤:
