×ðÁú¿­Ê±

sqlÖÐcase whenÓï¾äµÄÓ÷¨

case when Óï¾äÓÃÓÚ sql ÖÐƾָ֤¶¨Ìõ¼þÆÀ¹À±í´ïʽ²¢·µ»Ø²î±ðÖµ¡£ËüµÄÓï·¨°üÀ¨ when ×Ӿ䣨Ìõ¼þ±í´ïʽºÍ·µ»Ø±í´ïʽ£©¡¢else ×Ӿ䣨ĬÈϱí´ïʽ£©ºÍ end Òªº¦×Ö¡£Ëü¿ÉÓÃÓÚÖÖÖÖ³¡¾° £¬°üÀ¨·ÖÅÉÖµ¡¢ÐÞ¸ÄЧ¹ûºÍת»»Êý¾ÝÃûÌá£

CASE WHEN Óï¾äÔÚ SQL ÖеÄÓ÷¨

CASE WHEN Óï¾äÊÇÒ»ÖÖ SQL ÅÌÎÊÖеĿØÖÆÁ÷Óï¾ä £¬ÓÃÓÚƾָ֤¶¨Ìõ¼þÆÀ¹À²î±ðµÄ±í´ïʽ¡£ÆäÓï·¨ÈçÏ£º

CASE
  WHEN <condition> THEN <expression>
  WHEN <condition> THEN <expression>
  ...
  ELSE <default_expression>
END</default_expression></expression></condition></expression></condition>

µÇ¼ºó¸´ÖÆ

Ó÷¨£º

Ìõ¼þ£¨Condition£©£ºÖ¸¶¨ÓÃÓÚÆÀ¹À±í´ïʽµÄ²¼¶û±í´ïʽ¡£

±í´ïʽ£¨Expression£©£ºÈôÊÇÌõ¼þΪÕæ £¬ÔòÇóÖµ²¢·µ»ØµÄÖµ¡£

ĬÈϱí´ïʽ£¨Default_expression£©£ºµ±Ã»ÓÐÌõ¼þΪÕæʱ £¬ÇóÖµ²¢·µ»ØµÄÖµ¡£

°ì·¨£º

È·¶¨ÒªÆÀ¹ÀµÄÌõ¼þ£ºÈ·¶¨ÄãÏë»ùÓÚʲôÌõ¼þ·µ»Ø²î±ðµÄÖµ¡£

±àд WHEN ×Ӿ䣺¹ØÓÚÿ¸öÌõ¼þ £¬Ê¹Óà WHEN ×Ó¾äÖ¸¶¨Ìõ¼þºÍÒª·µ»ØµÄ±í´ïʽ¡£

Ìí¼Ó ELSE ×Ӿ䣺ָ¶¨µ±ËùÓÐÌõ¼þ¶¼²»Öª×ãʱµÄĬÈÏ·µ»ØÖµ£¨¿ÉÑ¡£©¡£

¿¢Ê CASE Óï¾ä£ºÊ¹Óà END Òªº¦×Ö¿¢Ê CASE Óï¾ä¡£

ʾÀý£º

Ҫƾ֤¿Í»§µÄÄêËê×éΪ¿Í»§·ÖÅÉÕÛ¿Û £¬¿ÉÒÔʹÓÃÒÔÏ SQL ÅÌÎÊ£º

SELECT CASE
  WHEN age = 18 AND age = 25 AND age <p>ÔÚÕâ¸öÅÌÎÊÖУº</p>

µÇ¼ºó¸´ÖÆ

Ìõ¼þƾ֤¿Í»§µÄÄêËê¶Ô¿Í»§¾ÙÐзÖ×é¡£

±í´ïʽָ¶¨Ã¿¸öÄêËê×éµÄÕÛ¿ÛÂÊ¡£

ĬÈϱí´ïʽΪ 0.25 £¬ÌåÏÖ 35 ËêÒÔÉϵÄËùÓпͻ§µÄÕÛ¿ÛÂÊ¡£

ÓÃÀý£º

CASE WHEN Óï¾ä¿ÉÓÃÓÚÖÖÖÖ³¡¾° £¬°üÀ¨£º

ƾ֤Ìõ¼þ·ÖÅɲî±ðµÄÖµ£¨ÈçÕÛ¿Û»ò·ÖÀࣩ¡£

»ùÓÚÌõ¼þÐÞ¸ÄÅÌÎÊЧ¹û£¨Èç¹ýÂË»òÅÅÐò£©¡£

ת»»Êý¾ÝÃûÌã¨È罫Îı¾×ª»»ÎªÊý×Ö£©¡£

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

13452372176

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

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

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿