Sql server 在存储过程中排列asc的排序类型

Sql server 在存储过程中排列asc的排序类型,sql-server,vb.net,Sql Server,Vb.net,我的数据库中有如下数据: 0 1 2 1 0 3,我想按升序排序,第一条记录应该是1,而不是0。我想要这样的输出: 1 1 2 3 0 0. 有人帮我吗?我有这样一个存储过程: select * from table order by number ascending 输出为0 1 2 3 有人吗?应该很简单。您可以使用where条件选择两次,然后使用union all select * into #temp from table where id <> 0 order by i

我的数据库中有如下数据: 0 1 2 1 0 3,我想按升序排序,第一条记录应该是1,而不是0。我想要这样的输出: 1 1 2 3 0 0. 有人帮我吗?我有这样一个存储过程:

select * from table order by number ascending 
输出为0 1 2 3


有人吗?

应该很简单。您可以使用where条件选择两次,然后使用union all

select * into #temp from table where id <> 0 order by id

select * from #temp
union all
select * from table where id = 0

它应该很简单。您可以使用where条件选择两次并使用union all

select * into #temp from table where id <> 0 order by id

select * from #temp
union all
select * from table where id = 0
这只需更改排序顺序,如果您想添加额外的字段,它很容易扩展


这只需更改排序顺序,如果您想添加额外字段,则可以轻松扩展。

union all不起作用。如果存在order by关键字/Syntax,则可以将该数据复制到临时表,然后在您的帮助下执行union all。它行得通,但我应该选短一点的。hehe.union all不起作用如果存在order by关键字/SYNTAX,您可以将该数据复制到临时表中,然后在您的帮助下执行union all。它行得通,但我应该选短一点的。呵呵,干得好。。。然而,请注意,在您的表中没有任何数字高于'THEN 999999'的好黑客。。。不过,请注意,您表中的数字都不高于'THEN 999999'