mysql - SQL: get min and max value along with another respective column for each value -


this question has answer here:

-------------------------------- |uid |lesson_score |date       | -------------------------------- |1   |2            |1391023460 | |1   |4            |1391023518 | |2   |3            |1391023557 | |1   |8            |1391023596 | -------------------------------- 

how determine maximum , minimum scores particular user, , respective date?

so far have this:

select max(lesson_score) max_lesson_score, min(lesson_score) min_lesson_score, date user_progress  uid = 1 

what need this:

min: 2, 1391023460 max: 8, 1391023460 

i know it's returning correct min , max score, it's returning 1 date, , i'm not sure date it's returning...

thanks!

your query not legal sql, because there different data values min , max scores.

the query not simple because want return min , max in different rows.

select lesson_score, date  user_progress uid = 1 , (       lesson_score = (select max(lesson_score)                        user_progress                       uid = 1)    or (lesson_score = (select min(lesson_score)                       user_progress                       uid = 1)   ) 

and if have more 1 lesson_score equal min or max, rows showing it.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -