Microsoft Access query returning sequential numbers

前端 未结 2 1354
我在风中等你
我在风中等你 2021-01-21 16:49

Is there any way to create query in MS Access which returns sequential numbers of my choice? For example

10.1
10.2
10.3
10.4
10.5

or



        
2条回答
  •  时光取名叫无心
    2021-01-21 17:34

    You can use a simple Cartesian Query having a table with numbers from 0 to 9:

    SELECT 
        t1.Number + 
        t2.Number * 10 + 
        t3.Number * 100 + 
        t4.Number * 1000 As Factor
    FROM 
        tblNumber AS t1, 
        tblNumber AS t2,
        tblNumber AS t3, 
        tblNumber AS t4
    

    or - if you only need small series - just a table with numbers from 0 to 99.

    Then for your samples:

    SELECT 
        10 + 0.1 * [Number] AS [Value]
    FROM 
        tblNumber
    WHERE 
        [Number] Between 1 And 5
    

    and:

    SELECT 
        [Number] * 10 AS [Value]
    FROM 
        tblNumber
    WHERE 
        [Number] Between 2 And 10
    ORDER BY 
        [Number] * 10 Desc
    

    and:

    SELECT 
        DateAdd("h", [Number], #2015-04-10 12:00 PM#) AS [Date]
    FROM 
        tblNumber
    WHERE 
        [Number] Between 0 And 6
    

    Addendum

    A number series can also be built without a dedicated number table by using a system table as source:

    SELECT DISTINCT 
        [Tens]+[Ones] AS Factor, 
        10*Abs([Deca].[id] Mod 10) AS Tens, 
        Abs([Uno].[id] Mod 10) AS Ones
    FROM 
        msysobjects AS Uno, 
        msysobjects AS Deca;
    

提交回复
热议问题