Python + Sqlite 3 query with multiple conditions

Viewed 630

I want to query a table paths with 5 columns (user, trial , t, x, y) to get user, trial and t where first condition: x*x+y*y<100 and second condition: t has the max value.

I solved only the half of the problem, implemented the first condition:

query = '''
    SELECT user, trial , t, 
    FROM paths
    WHERE x*x+y*y<100
    '''

Got this: enter image description here

I must add the second condition such as only the user + trial with max value for t should be selected. Example: row 1226 5 2.348045

Please help me to find a solution. Thank you!

1 Answers

For SQLite3 specifically (it won't work with any SQL), you can simply change t to max(t) t in your SELECT statement. (Also, remove the dangling comma after t,).

If you need max for each user, add GROUP BY user at the end.

Related