如何在sqlserver中的表中以相反的顺序返回列数据 [英] how to return column data in reverse order in a table in sqlserver

查看:81
本文介绍了如何在sqlserver中的表中以相反的顺序返回列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai



i有桌子而且只有一栏

列数据是

col1

1

0

1

0



所以这里我想以col1的相反顺序呈现数据如下所示

col1

o

1

0

1



有多少种方法可以返回上面的订单以及我们如何退货?

请给我回答这个问题....

hai

i have table and in that only one column
the column data is
col1
1
0
1
0

so here i want to present the data in reverse order of col1 is like below
col1
o
1
0
1

how many ways are there to return result above order and how can we return?
please give me answer to this question....

推荐答案

第一种情况下的订单逻辑是什么?什么是订购密钥?与DESC一起使用!如果它是插入数据的自然顺序,则应该在选择时使用自动增量字段或时间戳以及该字段。表格不是excel表格。

尽管如此,不应该使用原始问题的答案,但它存在:

And what is the order logic in the first case? What is the ordering key? Use it in with DESC! If it is the natural order of inserting the data, you should use an autoincrement field or a timestamp and us that field when selecting. A table is not an excel sheet.
Still, although the answer to your original question should not be used, it exists:
select * from
    (select ROW_NUMBER() OVER (ORDER BY (SELECT 1)) RowNumber ,* from sys.databases) TMP
order by RowNumber desc



用查询替换带下划线的部分。这是一般方法,但在大多数情况下代表不必要的开销。您应该检查您的模型。


Replace the underlined part with your query. This is the general approach, but represent an unnecessary overhead in most cases. You should review your model.


这篇关于如何在sqlserver中的表中以相反的顺序返回列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆