简体   繁体   中英

Microsoft Access Query Sort Order

I am having an issue with the order by clause. Objective

Group like SSN together

I then would like to list by priority number. 1 being the highest priority number

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? 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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