簡體   English   中英

Select ENTITY_ID 其中 USER_ID 點的總和大於所有其他 USER_ID 點的總和

[英]Select ENTITY_ID where sum of USER_ID points is greater than the sum of every other USER_ID's points

我下表

table edits
- user_id
- entity_id
- points: smallint

一個用戶可以有多個相同的entity_id行。

我想返回一個 entity_id 列表,其中user: 1點的總和大於特定實體的任何其他用戶點的總和。 我猜這是group by [user_id, entity_id]having sum(user_id: 1) >= sum(user_id)組成的組完成的,但這就是我的知識結束的地方。

嗯。 . . 這是你想要的嗎?

select e.*
from edits e
where e.points < (select e2.points
                  from edits e2
                  where e2.entity_id = e.entity_id and e2.user_id = 1
                 ) and
      e.entity_id = ?;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM