Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 什么';优化案例陈述的最佳方式是什么?_Mysql_Sql - Fatal编程技术网

Mysql 什么';优化案例陈述的最佳方式是什么?

Mysql 什么';优化案例陈述的最佳方式是什么?,mysql,sql,Mysql,Sql,例如。。 我有三个case语句,我想把它们的值保存在一个变量中 Select Case when 1 then variable='123' else case when 2 then variable='456' else case when 3 then variable='123456' from table X where some conditions ; 试试这个例子 Select x.field, Case x.value when

例如。。 我有三个case语句,我想把它们的值保存在一个变量中

Select
    Case when 1 then variable='123' else
    case when 2 then variable='456' else
    case when 3 then variable='123456'
from 
table X where 
some conditions ;
试试这个例子

Select x.field,
    Case x.value 
    when 1 then '123'
    when 2 then '456'
    when 3 then '123456'
    ELSE '789'
    END AS variable
from 
table X where 
some conditions ;

您认为这里到底需要优化什么?使用一些比case语句更好的命令?更好的赋值方法,我的case语句包含复杂的条件,所以我觉得case不能提供这样的性能。在您的示例中,这可能是最好的方法。也许对于你们复杂的情况,会有更好的方法,但我们不知道那个些情况是什么。你们建议破译陈述还是用COALASCE代替case陈述?