在SQL中仅为元素选择n行

时间:2020-10-19 15:41:46

标签: sql greatest-n-per-group distinct-values

我有一个表,其中每个table2_id都有很多列,我只希望ID最多的5行

id | table_2_id | name
----------------------
1  | 1          |A
2  | 1          |B
3  | 1          |C
4  | 1          |D
5  | 1          |E
6  | 1          |F 
7  | 1          |F 
8  | 2          |G
9  | 3          |H 
10 | 3          |I

table_2_id中有7个元素中有1个,我想有5个

所以我想拥有

id | table_2_id | name
----------------------
3  | 1          |C
4  | 1          |D
5  | 1          |E
6  | 1          |F 
7  | 1          |F 
8  | 2          |G
9  | 3          |H 
10 | 3          |I

1 个答案:

答案 0 :(得分:0)

您可以使用import json,httplib connection = httplib.HTTPSConnection('parseapi.back4app.com', 443) connection.connect() connection.request('POST', '/files/a.mp3', open('a.mp3', 'rb').read(), { "X-Parse-Application-Id": "${APPLICATION_ID}", "X-Parse-REST-API-Key": "${REST_API_KEY}", "Content-Type": "audio/mpeg" }) result = json.loads(connection.getresponse().read())

connection.request('POST', '/classes/sounds', json.dumps({
       "displayText": "test",
       "audio": {
         "name": result["name"],
         "url:": result["url"],
         "__type": "File"
       }
     }), {
       "X-Parse-Application-Id": "${APPLICATION_ID}",
       "X-Parse-REST-API-Key": "${REST_API_KEY}",
       "Content-Type": "application/json"
     })
connection.getresponse().read()
相关问题