Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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查询,在底部显示数量为0的产品_Mysql_Tsql - Fatal编程技术网

MYsql查询,在底部显示数量为0的产品

MYsql查询,在底部显示数量为0的产品,mysql,tsql,Mysql,Tsql,我有一个MYSQL数据库和一个表产品。 在其他字段中,有Qty(产品数量)和ProductCode(产品代码)。 有些产品的数量为0。 我想在网格底部显示这些产品,其余的产品在网格顶部按ProductCode排序>0。 如果我说order by Qty desc,productcode,那么所有0个产品都会排在底部,但productcode的顺序不正确。 如果我说订单按产品代码asc,数量描述,那么我有一些0产品的顶部。 我尝试使用Union,首先是all>0的查询,然后是的查询Union将使用

我有一个MYSQL数据库和一个表产品。 在其他字段中,有Qty(产品数量)和ProductCode(产品代码)。 有些产品的数量为0。 我想在网格底部显示这些产品,其余的产品在网格顶部按ProductCode排序>0。 如果我说order by Qty desc,productcode,那么所有0个产品都会排在底部,但productcode的顺序不正确。 如果我说订单按产品代码asc,数量描述,那么我有一些0产品的顶部。
我尝试使用Union,首先是all>0的查询,然后是的查询Union将使用Subselect:

SELECT * FROM (SELECT Qty, Productcode FROM schema_name.Products WHERE Qty > 0 
               ORDER BY Productcode) AS a
UNION ALL
SELECT * FROM (SELECT Qty, Productcode FROM schema_name.Products WHERE Qty <= 0 
               ORDER BY Productcode) AS b ;

是的。谢谢