mysql - Fetch MIN and MAX in the same row -


After the

a table training_route that contains multiple rows each with a rowId , gpsLocation and a athleteId and consider the following:

  • minimum rowId Defines first place and
  • < / Li>
      rowId athleteId gpsLocation 100 1 "40.71,27,837, -74.00594130000002" & Lt; - 1 101 1 "41.12,34,872, -71.41300000022342" for athlete # 102 1 First place "42.12,34,872, -69.23112200022342" & lt; - Place 1 103 2 "39.59, 9, 3, 99, -74.00594130000002" for last athlete # & lt; - First place for athlete # 2 104 2 "38.9 0, 9 3,885, -73.31300000022342" 106 2 "37.12,34,872, -63.34215200022342" & lt; - Last place for athlete # 2 107 3 ...  

    I have been given the first and final position for the entire route by athlete ID, from the very query on the same line: < / P>

      athleteId firstLocation lastLocation 1 "40.71,27,837, -74.00594130000002" "42.12,34872, -69.23112200022342" 2 "39.59, 9, 3, 99, -74.00594130000002" "37.12,34,872, -63.34215200022342" 3 ... ...  

    How will mySQL query look like this

    PS

    < P> I've tried something like this:

     Select  training_route.athleteId, (SELECT training_route.gps Thanh training Se_ Prshikshn_rekha WHERE training_route.athleteId = route.athleteId by order of training_route.rowId ASC limit 1) first, (SELECT training_route.gps transfers training_route WHERE training_route.athleteId = training_route.rowId DESC by route.athleteId Order LIMIT 1) As a last resort, training_route.athleteId by WHERE training_Route.athleteId (1, 2, 3) group as a route from training_route;  

    But I have in terms of embarrassed because it totally unacceptable performance'm the best I've come up with so far. After

    itemprop = "text">

    should work with mysql

      select Min (rowid) minrowid, Max (rowid) maxrowid, athleteid training_route trmin.athleteid on Athleteid) Minmax interiors by the group = minmax.athleteid and trmin.minrowid = minmax.rowid insider Join training_route trmax on trmax.athleteid = minmax. athleteid join trmax.maxrowid = minmax.rowid   

    to view

    • for each player Minimum and maximum rowid mill
    • Repeat the table again with the table

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -