简体   繁体   中英

compare column of two rows of same table in mysql

I have a table name player_history containing history of player. in this table having column player_id, Final_position,meeting_code,race_no and beaten_time. If a player stood a first or second position the time will be same there are meeting code one day and in each meeting code there are maximum 10 races.

I want to select those records where 1st and second position beaten time are not same.

player_id Meeting_Code race_no final_position beaten_time
  1         0001          1         1             2
  2         0001          1         2             2
  1         0001          2         1             5
  2         0001          2         2             6        
... so on

Output should be:

player_id Meeting_Code race_no final_position beaten_time
  1         0001          2         1             5
  2         0001          2         2             6 

Also if it is not correct I want to update records of first position only.

Let table name be Test . Try to put Self Join or something like this:

Select t1.player_id t1.Meeting_Code t1.race_no t1.final_position t1.beaten_time
From Test t1
LEFT JOIN Test t2 ON t1.beaten_time != t2.beaten_time.

Try like this. It might work.

Check this it will work

SELECT *
FROM   table_name
GROUP BY player_id
HAVING count(beaten_time) = 1;

Try It:

select b.player_id,b.meeting_code,b.race_no,b.final_position,b.beaten_time 
from player_history a,player_history b
where  a.race_no = b.race_no and a.beaten_time != b.beaten_time;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM