±ítb id price lasttime ÉÏ´Îʱ¼ä thetime ±¾´Îʱ¼ä p ±êÖ¾ 3 »ò 4
Èç¹û±êÖ¾ p =3 ʱ¼ä¾ÍÈ¡ thetime select id,price from tb where p ='3' and thetime <getdate() Èç¹û±êÖ¾ p =4 ʱ¼ä¾ÍÈ¡ thetime select id,price from tb where p ='4' and lasttime <getdate()
ÎÒÏÖÔÚÓõÄÊÇunion all ·½Ê½´¦ÀíµÄ,µ«ÎÒÏëÓÃÒ»ÌõÓï¾äд³öÉÏÃæ¶þÌõµÄ½á¹û¡£ SQL code: SELECT * from TB WHERE CASE WHEN P='3' THEN thetime ELSE lasttime END <GETDATE()
SQL code: select * from tb where case p when '3' then thetime else lasttime end<getdate()