mysql - Combining between two queries -


i have 2 big queries, individually both work , produce want.

query 1:

select pt.map, pt.time, pt.jumps, pt.id playertimes pt auth = '[u:1:204506329]' , style = 0 order map; 

(in action, [u:1:204506329] variable)

query 2:

select count(*) rank playertimes pt left join users u on u.auth = pt.auth pt.time <= (     select time     playertimes     map = 'bhop_horsepoop_8' , style = 0 , auth = '[u:1:204506329]'     limit 1 ) , pt.map = 'bhop_horsepoop_8' , pt.style = 0 order time asc limit 1; 

(again, [u:1:204506329] , bhop_horsepoop_8 variables)

the purpose of query 1 retrieve list of maps, times, jumps , ids auth define.

the purpose of query 2, find auth's position ('rank') in playertimes table on defined map , style. intention, sum both of single query. receive both want in first query, , rank field every row retrieved in query 1.

this tried:

select pt.map, pt.time, pt.jumps, pt.id, (     select count(*) rank     playertimes pt     left join users u on u.auth = pt.auth     pt.time <= (         select time         playertimes         map = pt.map , style = 0 , auth = '[u:1:204506329]'         limit 1     ) , pt.map = map , pt.style = 0 order time asc limit 1 ) rank playertimes pt auth = '[u:1:204506329]' , style = 0 order map; 

the results ended being incorrect!

the following resultset of query (phpmyadmin):

query resultset

as see, rank same , should change every row. while want rank calculated according map of same row.

i'm stuck. (and explanation, if possible) appreciated!

update: have tried mike's solution, query ended with:

select * (   select pt.map, pt.time, pt.jumps, pt.id, pt.auth     playertimes pt         auth = '[u:1:204506329]' , style = 0             order map         )     left join     (         select count(*) rank             playertimes pt                 left join users u                     on u.auth = pt.auth                         pt.time <=(                             select time, auth                                 playertimes                                     map = a.map , style = 0 , auth = '[u:1:204506329]'                                         limit 1   )         , pt.map = a.map , pt.style = 0             order time asc                 limit 1                     ) b     on a.auth = b.auth; 

the following error mariadb returning:

 #1054 - unknown column 'a.map' in 'where clause' 

i'm not sure how fix one. but, tried filling where a.map constant string, output:

 #1241 - operand should contain 1 column(s) 

which of course because tried select both time , auth operand (while i'm supposed select 1 field), have otherwise on a.auth = b.auth throw error b.auth being unknown column in on clause.

update 2: have come partial solution, query works rank applies map define.

select a.map,        a.time,        a.jumps,        a.id,        a.auth,        b.rank   ( select pt.map,            pt.time,            pt.jumps,            pt.id,            pt.auth    playertimes pt    auth = '[u:1:204506329]'      , style = 0    order map ) left join   ( select count(*) rank,            pt.auth    playertimes pt    left join users u on u.auth = pt.auth    pt.time <=        ( select time         playertimes         map = 'bhop_horsepoop_8'           , style = 0           , auth = '[u:1:204506329]' limit 1 )      , pt.map = 'bhop_horsepoop_8'      , pt.style = 0    order time asc limit 1 ) b on a.auth = b.auth; 

i couldn't think of solution calculate rank current row.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -