search

Home  >  Q&A  >  body text

Newcomer, I would like to ask MySQL for advice on the sql statement for querying after judging and concatenating conditions.

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!

世界只因有你世界只因有你2811 days ago677

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦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));

    reply
    0
  • Cancelreply