php - Mysql - get 6 results before and after the desired value to make comparison chart -


today facing challenge me, solve multiple queries, little bit of php , other funny things, wondering whether mean can achieved single query and/or stored fn/procedure.

i explain myself better: in list of cities, need pick value (say "general expenses") of named city (say "rome").

pretty simple.

what is: have 6 records same value before , 6 after rome one. see something:

| position | city      | expenses | |    35    | paris     | 1364775  | |    36    | milan     | 1378499  | |    37    | new york  | 1385759  | |    38    | london    | 1398594  | |    39    | oslo      | 1404648  | |    40    | munchen   | 1414857  | |    41    | rome      | 1425773  | ***  <--this value need |    42    | dublin    | 1437588  | |    43    | athen     | 1447758  | |    44    | stockholm | 1458593  | |    46    | helsinki  | 1467489  | |    47    | moscow    | 1477484  | |    48    | kiev      | 1485665  | 

these values populate bars chart.

as can see there complexity level: position.

position must calculated on records.

so let's have 100 records, have ranking position 1 100, "limited 13" records must output.

any link, suggestion, tutorial or else me out that? thank in advance always.

edit position must calculated. not input value.

anyway, folks efforts.

select all_ranked.* (select rank        (select a.id             id2,             @currow := @currow + 1 rank             the_table             join                 (select @currow := 0) r                 order position desc             ) b)        b.id=1234567) rank_record, <--- 1 record - value of rank       (select a.id             id2,             @currow := @currow + 1 rank             the_table             join                 (select @currow := 0) r                 order position desc             ) all_ranked <--- ranked users all_ranked.rank>=rank_record.rank-6 , all_ranked.rank>=rank_record.rank+6 

create 2 queries joined in one. first gets position , second sets positions , cut's desired fragment


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -