T
T
TupaDev2021-12-22 02:48:28
Python
TupaDev, 2021-12-22 02:48:28

How to make top by data from sqlite3 table?

For example, I have data like this -

Country | UserID | Profit
US        1         100
US        12        98
US        13        10
US        5         8
US        2         5
IR        9         95
IR        3         90
IR        8         70
IR        4         56
IR        15        40


And after the output should become like this -
Country | UserID | Profit
US        1         100
US        12        98
US        13        10
IR        9         95
IR        3         90
IR        8         70


Who has more profit is higher

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-12-22
@TupaDev

Of course, the Profit field must be int:

result = cursor.execute('SELECT * FROM Users ORDER BY Profit DESC').fetchall()

for x in result:
  print(x)

('US', '1', 100)
('US', '12', 98)
('IR', '9', 95)
('IR', '3', 90)
('IR', '8', 70)
('IR', '4', 56)
('IR', '15', 40)
('US', '13', 10)
('US', '5', 8)
('US', '2', 5)

I hope you have a typo in your example:
Country | UserID | Profit
US        1         100
US        12        98
US        13        10 - Здесь
IR        9         95
IR        3         90
IR        8         70

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question