尊龙凯时人生就是搏

mysqlÖÐfromºóÃæÄܲ»¿É¸úcase

ÊÇµÄ £¬mysqlÔÊÐíÔÚfrom×Ó¾äÖÐʹÓÃcase±í´ïʽÀ´Ñ¡ÔñÌض¨ÐÐ £¬Ó﷨Ϊ£ºselect … from table_name where and case when then when then else end as £¬ÆäÖÐ

MySQL FROM ºóÃæÄÜ·ñʹÓà CASE ±í´ïʽ£¿

ÃÕµ×£º

¿ÉÒÔ

ÏêϸڹÊÍ£º

MySQL ÔÊÐíÔÚ FROM ×Ó¾äÖÐʹÓà CASE ±í´ïʽÀ´´Ó±íÖÐÑ¡ÔñÌض¨ÐÐ ¡£CASE ±í´ïʽʵÖÊÉÏÊÇÒ»¸öÌõ¼þÓï¾ä £¬¿ÉÒÔƾ֤¸ø¶¨µÄÌõ¼þ·µ»Ø²î±ðµÄÖµ ¡£

Óï·¨£º

SELECT ...
FROM table_name
WHERE <filter_condition>
AND CASE
    WHEN <condition1> THEN <value>
    WHEN <condition2> THEN <value>
    ELSE <default_value>
END AS <alias></alias></default_value></value></condition2></value></condition1></filter_condition>

µÇ¼ºó¸´ÖÆ

ÆäÖУº

ÊÇÔÚÓ¦Óà CASE ±í´ïʽ֮ǰ±ØÐèÖª×ãµÄÌõ¼þ ¡£

ºÍ ÊÇÒªÆÀ¹ÀµÄÌõ¼þ ¡£

ÊÇƾ֤Ìõ¼þ·µ»ØµÄÖµ ¡£

ÊÇÈôÊÇûÓÐÌõ¼þÆ¥Åäʱ·µ»ØµÄĬÈÏÖµ ¡£

ÊÇΪ CASE ±í´ïʽЧ¹û·ÖÅɵÄÓÖÃû ¡£

ʾÀý£º

¼ÙÉèÓÐÒ»¸ö “customers” ±í £¬°üÀ¨ÒÔÏÂÁУº

customer_id

name

country

ÎÒÃÇ¿ÉÒÔʹÓà CASE ±í´ïʽ´Ó±íÖÐÑ¡ÔñÀ´×ÔÌض¨¹ú¼Ò/µØÇøµÄ¿Í»§£º

SELECT *
FROM customers
WHERE country = 'United States'
AND CASE
    WHEN age &gt; 18 THEN 'Adult'
    WHEN age <p>´ËÅÌÎʽ«·µ»ØËùÓÐÀ´×ÔÃÀ¹úµÄ¿Í»§£¬²¢Æ¾Ö¤ÄêË꽫ËûÃÇ·ÖÀàΪ³ÉÄêÈË¡¢Î´³ÉÄêÈË»òδ֪¡£</p>

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇmysqlÖÐfromºóÃæÄܲ»¿É¸úcaseµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

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