Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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-按第1列排序,如果不为空,则按第2列排序_Mysql_Sql Order By - Fatal编程技术网

MySQL-按第1列排序,如果不为空,则按第2列排序

MySQL-按第1列排序,如果不为空,则按第2列排序,mysql,sql-order-by,Mysql,Sql Order By,我曾尝试在MySQL中订购一些结果,但我不确定我想要的是一个订单是否可行 drop temporary table if exists temp; create temporary table temp ( doc integer not null, dest integer null ); insert into temp (doc, dest) values (1, 0), (2, 0), (3, 100000), (3, 142000

我曾尝试在MySQL中订购一些结果,但我不确定我想要的是一个订单是否可行

drop temporary table if exists temp;  

create temporary table temp (  
  doc integer not null,  
  dest integer null  
);  

insert into temp  
(doc, dest)  
values  
(1, 0),  
(2, 0),  
(3, 100000),  
(3, 142000),  
(4, 100000),  
(4, 142000),  
(5, 0),  
(6, 0),  
(7, 100000),  
(7, 142000),  
(8, 100000),  
(8, 142000),  
(9, 100000),  
(9, 142000);  
我想按单据订购,但如果dest不为空,则按dest订购doc而不是doc。
这将使:

(1, 0)  
(2, 0)  
(3, 100000)  
(4, 100000)  
(3, 142000)  
(4, 142000)  
(5, 0)  
(6, 0)  
(7, 100000)  
(8, 100000)  
(9, 100000)  
(7, 142000)  
(8, 142000)  
(9, 142000)
谢谢你的帮助

问候,


格雷格

你能把一行中的数据是(3,空)(4,空)的情况包括在内吗对不起,我不太明白你的问题。如果您的意思是,对于同时具有dest!=0的值,这是不可能发生的。我的意思是当dest为null时,您的输出会是什么样子。输出查找(10,null)(0,null)的内容也会与不存在null的内容重复(如果您愿意,在我的示例中null是0)