mysql case when »ù´¡Ó÷¨
CASE
¼ÆËãÌõ¼þÁÐ±í²¢·µ»Ø¶à¸ö¿ÉÄܽá¹û±í´ïʽ֮һ¡£
CASE ¾ßÓÐÁ½ÖÖ¸ñʽ£º
¼òµ¥ CASE º¯Êý½«Ä³¸ö±í´ïʽÓëÒ»×é¼òµ¥±í´ïʽ½øÐбȽÏÒÔÈ·¶¨½á¹û¡£
CASE ËÑË÷º¯Êý¼ÆËãÒ»×é²¼¶û±í´ïʽÒÔÈ·¶¨½á¹û¡£
Á½ÖÖ¸ñʽ¶¼Ö§³Ö¿ÉÑ¡µÄ ELSE ²ÎÊý¡£
Óï·¨
¼òµ¥ CASE º¯Êý£º
CASE input_expression
WHEN when_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
END
CASE ËÑË÷º¯Êý£º
CASE
WHEN Boolean_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
END
²ÎÊý
input_expression
ÊÇʹÓüòµ¥ CASE ¸ñʽʱËù¼ÆËãµÄ±í´ïʽ¡£Input_expression ÊÇÈκÎÓÐЧµÄ Microsoft® SQL Server™ ±í´ïʽ¡£
WHEN when_expression
ʹÓüòµ¥ CASE ¸ñʽʱ input_expression Ëù±È½ÏµÄ¼òµ¥±í´ïʽ¡£When_expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£Input_expression ºÍÿ¸ö when_expression µÄÊý¾ÝÀàÐͱØÐëÏàͬ£¬»òÕßÊÇÒþÐÔת»»¡£
n
ռλ·û£¬±íÃ÷¿ÉÒÔʹÓöà¸ö WHEN when_expression THEN result_expression ×Ó¾ä»ò WHEN Boolean_expression THEN result_expression ×Ӿ䡣
THEN result_expression
µ± input_expression = when_expression ȡֵΪ TRUE£¬»òÕß Boolean_expression ȡֵΪ TRUE ʱ·µ»ØµÄ±í´ïʽ¡£result expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£
ELSE else_result_expression
µ±±È½ÏÔËËãȡֵ²»Îª TRUE ʱ·µ»ØµÄ±í´ïʽ¡£Èç¹ûÊ¡ÂԴ˲ÎÊý²¢ÇұȽÏÔËËãȡֵ²»Îª TRUE£¬CASE ½«·µ»Ø NULL Öµ¡£Else_result_expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£Else_result_expression ºÍËùÓÐ result_expression µÄÊý¾ÝÀàÐͱØÐëÏàͬ£¬»òÕß±ØÐëÊÇÒþÐÔת»»¡£
WHEN Boolean_expression
ʹÓà CASE ËÑË÷¸ñʽʱËù¼ÆËãµÄ²¼¶û±í´ïʽ¡£Boolean_expression ÊÇÈÎÒâÓÐЧµÄ²¼¶û±í´ïʽ¡£
½á¹ûÀàÐÍ
´Ó result_expressions ºÍ¿ÉÑ¡ else_result_expression µÄÀàÐͼ¯ºÏÖзµ»Ø×î¸ßµÄÓÅÏȹæÔòÀàÐÍ¡£Óйظü¶àÐÅÏ¢£¬Çë²Î¼ûÊý¾ÝÀàÐ͵ÄÓÅÏÈ˳Ðò¡£
½á¹ûÖµ
¼òµ¥ CASE º¯Êý£º
¼ÆËã input_expression£¬È»ºó°´Ö¸¶
Ïà¹ØÎĵµ£º
¡¡Ò»Ö±À§ÈÅÎÒ¿ì°ëÄêµÄÎÊÌâÖÕÓڵõ½½â¾ö, ·þÎñÆ÷µÄmysqlÀÏÊÇÔËÐÐÒ»¶Îʱ¼ä,×Ô¶¯Í£Ö¹ÁË,±ØÐëÊÖ¶¯Æô¶¯. !
¡¡¡¡ÎÒÕÒÆ«ÍøÉÏËùÓеķ½·¨,µ«Ã»ÓÐÒ»¸öÄܽâ¾ö,ʲôÐÞ¸ÄÅäÖÃÎļþ°¡.¶¨Ê±Æô¶¯.¶¼Ã»Ð§¹û. ¸ù¾Ýר¼Ò¹Û²ì£¬ÕâÑùµÄÀíÂÛºÍÏÖÏó¶¼ÊÇÖµµÃ¸÷λվ³¤Éî˼µÄ£¬ËùÒÔÏ£Íû´ó¼Ò¶à×öÑо¿Ñ§Ï°£¬ÕùÈ¡×ܽá³ö¸ü¶à¸üºÃµÄ¾Ñé!
¡¡¡¡Õâ¸ö·½·¨ÊÇÎÒ ......
¾ÍÏóÐí¶àµÄPHP¿ª·¢ÕßÒ»Ñù£¬ÔÚ¸Õ¿ªÊ¼½¨Á¢¶¯Ì¬ÍøÕ¾µÄʱºò£¬ÎÒ¶¼ÊÇʹÓÃÏà¶Ô¼òµ¥
µÄÊý¾Ý½á¹¹¡£PHPÔÚÁ¬½ÓÊý¾Ý¿â·½ÃæµÄȷʵÊÇÊ®·Ö·½±ã£¨ÒëÕß×¢£ºÓÐЩÈËÈÏΪPHPÔÚÁ¬½Ó²»Í¬Êý¾Ý¿âʱûÓÐÒ»¸öͳһµÄ½Ó¿Ú£¬²»Ì«·½±ã£¬ÆäʵÕâ¿ÉÒÔͨ¹ýһЩÀ©
Õ¹¿âÀ´×öµ½ÕâÒ»µã£©£¬ÄãÎÞÐè¿´´óÁ¿µÄÉè¼ÆÎĵµ¾Í¿ÉÒÔ½¨Á¢ºÍʹÓÃÊý¾Ý¿â£¬ÕâÒ²ÊÇPHP»ñµÃ³É¹¦µÄÖ÷ ......
Õ⼸ÌìLinux·þÎñÆ÷ºÜÂý,ºÜ׿±ÕÒ²»µ½½â¾ö°ì·¨!ºó°Ù¶ÈÏà¹Ø×ÖÑÛ,²éÕÒµ½ÊÇMySQLµÄÎÊÌâ,
ÈçÏÂΪ½â¾ö·½°¸
:
Á¬½ÓMySQLËÙ¶ÈÂýµÄ½â¾ö·½·¨.
PHPÔ¶³ÌÁ¬½ÓMYSQLËÙ¶ÈÂý,ÓÐʱԶ³ÌÁ¬½Óµ½MYSQLÓÃʱ4-20Ãë²»µÈ,±¾µØÁ¬½ÓMYSQLÕý³£,³öÏÖÕâÖÖÎÊÌâµÄÖ÷ÒªÔÒòÊÇ,ĬÈϰ²×°µÄ
MYSQL¿ªÆôÁËDNSµÄ·´Ïò½âÎö,ÔÚMY.CNF(UNIX»òLINUXϵͳÏÂ)»òMY.INI ......
MySQ×Ö·ûÀàÐÍ´óÖ¿ÉÒÔ·Ö³É(MySQL 5.0)£º
CHAR(M)£º0-255×Ö½Ú
VARCHAR(M)£º0-65535×Ö½Ú
TINYBLOB¡¢MEDIUMBLOB¡¢BLOB¡¢LONGBLOB(ʵ¼Ê³¤¶È·Ö±ð+1,3,2,4)
TINYTEXT¡¢MEDIUMTEXT¡¢TEXT¡¢LONGTEXT(ʵ¼Ê³¤¶È·Ö±ð+1,3,2,4)
BINARY(M):0-M×Ö½Ú
VARBINARY(M):ʵ¼Ê³¤¶È+1
MySQLÆäËûÀàÐÍ´óÖ¿ÉÒÔ·Ö³É(MySQL ......