I want to implement the statement that when b.phase>2, execute the splicing condition: AND unix_timestamp()> second_end_time
Otherwise, the splicing condition: AND unix_timestamp()> thirdly_end_time
Can you please tell me how to write this SQL?
SELECT * FROM data a, race b
WHERE
a.race_id = b.race_id
IF (b.phase > 2, AND unix_timestamp()> second_end_time , AND unix_timestamp()> thirdly_end_time)
AND user_id = 123
The above is written randomly by myself, the grammar is not correct, please give me some advice!
伊谢尔伦2017-05-18 10:47:28
SELECT * FROM data a,race b WHERE a.race_id=b.race_id AND ((b.phase>2 AND UNIX_TIMESTAMP()>second_end_time) OR (b.phase<=2 AND UNIX_TIMESTAMP()>thirdly_end_time));