【问题标题】:How to Sort the rows in Ms-Access Table using only 1 row?如何仅使用 1 行对 Ms-Access 表中的行进行排序?
【发布时间】:2020-04-24 01:28:17
【问题描述】:

我正在尝试仅使用 1 列对我的数据库 ms-access 中的一个表进行排序。 列的值是这样的:

PartMaterial
---------------------
C90X61Y13B
C90X61Y13D
C90X61Y1B
--------------------

我没有把所有的数据都放在这里,因为它太多了。

但我试过这个 sql:

SELECT DISTINCT PartMaterial FROM tblMaterialMark ORDER BY PartMaterial ASC

但是结果是这样的:

PartMaterial
---------------------
C90X61Y13B
C90X61Y13D
C90X61Y1B
--------------------

这是错误的,因为C90X61Y1B 应该是第一个。

正确的输出:

PartMaterial
---------------------
C90X61Y1B
C90X61Y13B
C90X61Y13D
--------------------

我怎样才能将这些项目以整数和字符串结合的升序排序?

【问题讨论】:

    标签: sql ms-access


    【解决方案1】:

    这是按字母顺序排列的。也许你想要长度:

    ORDER BY LEN(PartMaterial),  PartMaterial
    

    如果这不适用于SELECT DISTINCT,您可以尝试使用GROUP BY

    SELECT PartMaterial
    FROM tblMaterialMark 
    GROUP BY PartMaterial
    ORDER BY LEN(PartMaterial),  PartMaterial
    

    【讨论】:

    • 如何使用DISTINCT 先生?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2021-01-13
    • 1970-01-01
    相关资源
    最近更新 更多