×ðÁú¿­Ê±¹ÙÍøµÇ¼

sqlÖÐwhenÓ÷¨

sql ÖÐ when ×Ó¾äÓÃÓÚÔÚ case ±í´ïʽÖÐÖ¸¶¨Ìõ¼þ²¢·µ»ØÏìÓ¦Êä³ö¡£Óï·¨ÈçÏ£ºcase when condition then result end¡£Ìõ¼þΪ true ʱ £¬·µ»Ø¶ÔÓ¦µÄЧ¹û¡£

SQL ÖÐ WHEN Ó÷¨

ʲôÊÇ WHEN ×Ӿ䣿

WHEN ×Ó¾äÓÃÓÚÔÚ CASE ±í´ïʽÖÐÖ¸¶¨Ìõ¼þ²¢·µ»ØÏìÓ¦µÄÊä³ö¡£

Óï·¨£º

CASE
  WHEN condition1 THEN result1
  WHEN condition2 THEN result2
  ...
  ELSE result_default  -- ¿ÉÑ¡
END

µÇ¼ºó¸´ÖÆ

ÔõÑùʹÓà WHEN ×Ӿ䣿

Ö¸¶¨Ìõ¼þ£ºcondition1¡¢condition2 µÈÌåÏÖÒªÆÀ¹ÀµÄÌõ¼þ¡£Ð§¹ûΪ TRUE ʱ £¬½«Ö´ÐжÔÓ¦µÄÊä³ö¡£

·µ»ØÊä³ö£ºresult1¡¢result2 µÈÊÇÖª×ãÌõ¼þºó·µ»ØµÄÖµ¡£

ĬÈÏÊä³ö£¨¿ÉÑ¡£©£ºELSE ×Ó¾äÖ¸¶¨µ±ËùÓÐÌõ¼þ¶¼²»Öª×ãʱµÄĬÈÏÊä³öÖµ¡£ÈôÊÇδָ¶¨ ELSE £¬Ôò·µ»Ø NULL¡£

ʾÀý£º

-- ƾ֤Ч¹ûÅÌËãÆ·¼¶
CASE
  WHEN grade >= 90 THEN 'ÓŵÈ'
  WHEN grade >= 80 THEN 'ÓÅÒì'
  WHEN grade >= 70 THEN 'ÖеÈ'
  ELSE 'ȱ·¦¸ñ'
END

µÇ¼ºó¸´ÖÆ

×¢ÖØÊÂÏ

WHEN ×Ӿ䰴˳ÐòÆÀ¹À¡£Ò»µ©Öª×ãij¸öÌõ¼þ £¬½«×èÖ¹ÆÀ¹À²¢·µ»ØÏìÓ¦µÄÊä³ö¡£

CASE ±í´ïʽ¿ÉÒÔǶÌס£

WHEN ×Ó¾ä¿ÉÓÃÓÚÅÌÎÊ¡¢¸üкͲåÈëÓï¾äÖС£

ÒÔÉϾÍÊÇsqlÖÐwhenÓ÷¨µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ