简体   繁体   English

Microsoft Access查询排序顺序

[英]Microsoft Access Query Sort Order

I am having an issue with the order by clause. 我对order by子句有疑问。 Objective 目的

Group like SSN together 像SSN一样分组

I then would like to list by priority number. 然后,我想按优先级列出。 1 being the highest priority number 1是最高优先级数字

Query 询问

SELECT DRS_FILE.AGENCY, DRS_FILE.P1, DRS_FILE.FUND, DRS_FILE.ACCOUNT, DRS_FILE.LNAME, DRS_FILE.FNAME AS FNAME, DRS_FILE.SSN, DRS_FILE.PRIOR, DRS_FILE.BALDUE, DRS_FILE.BALDUE AS DRSBAL, DRS_FILE.FILL1, DRS_FILE.FILEDATE, DRS_FILE.FILL2
FROM DRS_FILE
ORDER BY DRS_FILE.SSN, DRS_FILE.P1;

However no matter how much I play around with the query the date is still out of order, see my results below. 但是,无论我处理多少查询,日期仍然是混乱的,请参阅下面的结果。

AGENCY     P1    FUND     LNAME     FNAME    SSN        PRIOR       FILEDATE    FILL2
6909       28    K        SWASEY    JOHN    999999999   051         190117 
2620       8     L        SWASEY    JOHN    999999999   052         190117

If you notice the in the P1 column I am using as the second order by clause but the order is incorrect seeing as though the priority number 8 should be higher than 28. Can someone help me to figure this out? 如果您注意到我在P1列中使用的是第二个by by子句,但该顺序不正确,好像优先级数字8应该高于28。有人可以帮我解决这个问题吗? Why is this happening? 为什么会这样呢? What am I doing wrong? 我究竟做错了什么? I have tried adding ASC and DESC to each of the fields in the order by clause to no avial. 我试过在order by子句中将ASC和DESC添加到每个字段中,这是没有意义的。

The funny thing is it works for some records and for others the results are out of order as shown above. 有趣的是,它适用于某些记录,而对于另一些记录,结果却是乱序的,如上所示。

您的“数字”可能是文本,因此请使用Val()转换为数字:

ORDER BY DRS_FILE.SSN, Val(DRS_FILE.P1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM