如何在sql访问中进行分段排序 [英] How to segment sort in sql access

查看:89
本文介绍了如何在sql访问中进行分段排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好亲爱的,

请你帮我。

我在Ms Access中有一个表包含这样的数据

ID Name

1 Dara

2 Somi

3 Vicheka

4 Sokun

5 Chann

6 Rith

7 Kaka

8 Nyla

9 sun

10 Lolana



我想在查询或SQL代码中这样排序,...

3 Vicheka

2 Somi

1 Dara

6 Rith

5 Chann

4 Sokun

9 sun

8 Nyla

7 Kaka

10 Lolana



你能帮忙吗?我喜欢下面的内容吗?

等待所有亲爱的结果。

Hello dear,
Can u help me, please.
I have a Table in Ms Access contain data like this
ID Name
1 Dara
2 Somi
3 Vicheka
4 Sokun
5 Chann
6 Rith
7 Kaka
8 Nyla
9 sun
10 Lolana

I want to sort like this in Query or SQL Code, ...
3 Vicheka
2 Somi
1 Dara
6 Rith
5 Chann
4 Sokun
9 sun
8 Nyla
7 Kaka
10 Lolana

Can you help me do like below?
I waiting for result from all dear.

推荐答案

是的你可以:

Yes you can:
SELECT 
    ID, [Name]
FROM 
    tblYourTable
ORDER BY 
    ([ID]-1) \ 3, ID DESC;



注意整数除法的反斜杠。


Note the backslash for integer division.


由于没有排序要做(你需要的顺序不能用比较运算符表示),你必须在表中添加第三列,例如OrderNumber,您将在其中放置您希望它出现的行的索引。

然后,在您的查询中,您只需要在新列上添加ORDER BY子句。
As there is no sorting to do (the order you need cannot be expressed with comparison operators), you have to add a third column to your table, named for example OrderNumber, where you will put the index of the line in which you want it to appear.
Then, in your query, you just have to add a ORDER BY clause on the new column.


这篇关于如何在sql访问中进行分段排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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