sql - Using INNER JOIN and MAX(), to return same row as MAX -
for reason, can't query return result i'm looking for. i'll explain after outlining situation...
there 2 tables, 1 players , 1 matches. within each match, player gets rating (float/decimal) based on position played in. rating may improve in 1 position, different/better in others. therefore, want able see max(rating) , pos max obtained in, alongside players details.
so, idea following:
select * players inner join(select pid, max(rating) a, pos matches group pid) b on b.pid = players.ypid players.ytid = '2010591' , players.status = '1' order ypromdate asc, ydob asc
this return of player's details , max rating, if player has played in multiple matches (hence group by) first record returned pos. example, if player1 got rating of 5 defender , 6 forward, query return 6 defender
if more information required, i'm happy provide!
thanks in advance..feel i've taken query down wrong route..
edit answer questions posted:
software: mysql
apache/2.2.15 (centos)
database client version: libmysql - 5.1.69
sample data, cut down save time:
matches table: id, matchid, matchdate, position, timeplayed, rating, pid
(149, 77221704, '2013-08-12 15:00:00', 100, 90, 1.5, 143569504),(150, 77221705, '2013-09-12 15:00:00', 103, 90, 3, 143569504)
players table: pid, ytid, status (143569504, 2010591, 1)
expected outcome:
pid, ytid, status, pos, max(rating) 143569504, 2010591, 1, 103, 3
current outcome:
pid, ytid, status, pos, max(rating) 143569504, 2010591, 1, 100, 3
something should work
select yourfields (not of them) players p join matches m on m.pid = p.pid join (select pid, max(rating) maxrating matches group pid) temp on p.pid = temp.pid , rating = maxrating etc
Comments
Post a Comment