Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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 有人能解释一下这个sql查询是如何工作的吗。分批订货_Mysql_Sql Order By - Fatal编程技术网

Mysql 有人能解释一下这个sql查询是如何工作的吗。分批订货

Mysql 有人能解释一下这个sql查询是如何工作的吗。分批订货,mysql,sql-order-by,Mysql,Sql Order By,**问题--为每个客户返回客户ID和地区 -按区域对输出中的行进行排序 -在非NULL值之后最后排序NULL select custid , region from sales.Customers order by case when region is null then 1 else 0 end , region 将查询更改为: select custid , region , case when region is null the

**问题--为每个客户返回客户ID和地区 -按区域对输出中的行进行排序 -在非NULL值之后最后排序NULL

select custid
     , region
  from sales.Customers
 order 
    by case when region is null then 1 else 0 end
     , region

将查询更改为:

select custid
     , region
     , case when region is null then 1 else 0 end sorter
  from sales.Customers
现在您可以看到它在做什么了吗?

当区域为空时,则1 else 0 end在区域为空时产生1,否则产生0。由于1>0,将在非null值之后排序null。如果这是你不明白的。否则,你需要更精确地解释你实际上不理解的东西。