2

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!

3
  • 1
    Pick one from [python] [sqlite3] multiple WHERE Commented Mar 30, 2020 at 21:24
  • I'm not quite sure what "t has the max value" means. Could you explain? Is t greater than x and y, greater than user or trial? Commented Mar 30, 2020 at 21:59
  • The sqlite website has a lot of documentation, much of which seems to be geared to those who already know SQL. So I would suggest you take a look at www.sqlitetutorial.net. That site gives lots of examples of the different features of the SQL dialect as understood by sqlite. Commented Mar 30, 2020 at 23:18

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.