请帮我写一个Django查询和MySql查询,我有一个像这样的表molesdetails:
+---+ +--------+ +----------+ +----------+
|id | |user_id | | ref | | set |
+---+ +--------+ +----------+ +----------+
|1 | | 1 | | 1 | | 1 |
|2 | | 1 | | 1 | | 2 |
|3 | | 1 | | 2 | | 3 |
|4 | | 2 | | 1 | | 1 |
|5 | | 2 | | 1 | | 2 |
|6 | | 2 | | 2 | | 3 |
|7 | | 1 | | 2 | | 4 |
+---+ +--------+ +----------+ +----------+
我希望我应该从集合最大的查询中获得特定用户 id 的不同 ref。就像我想要一些这样的东西user id = 1
:
+---+ +--------+ +----------+ +----------+
|id | |user_id | | ref | | set |
+---+ +--------+ +----------+ +----------+
|2 | | 1 | | 1 | | 2 |
|7 | | 1 | | 2 | | 4 |
+---+ +--------+ +----------+ +----------+
请帮助我编写 sql 查询,因为这对我来说很难达到这个结果,谢谢。