获得一对 table 的所有 ID 的最大值
get the max value of a couple for all ids of a table
我是 sql 的初学者,我想知道如何为两个连接表的每个 id 获取几个整数的最大值?
到目前为止我做了什么:
SELECT
Reduced_T_Rappro_N.[Rente RES] AS Rente_RES,
Reduced_T_Rappro_N.[Montant capital constitutif] AS Montant_Capital_Consitutif_N,
[Reduced_T_Rappro_N - 1].[Montant capital constitutif] AS [ "Montant_Capital_Constitutif_N-1" ],
IIf(
[Reduced_T_Rappro_N - 1].[Montant capital constitutif] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant capital constitutif] - [Reduced_T_Rappro_N - 1].[Montant capital constitutif]
)/ [Reduced_T_Rappro_N - 1].[Montant capital constitutif]
)* 100 AS [ "Evolution capital constitutif" ],
[Reduced_T_Rappro_N].[Montant Sous Rente],
[Reduced_T_Rappro_N - 1].[Montant Sous Rente],
(
IIf(
[Reduced_T_Rappro_N - 1].[Montant Sous Rente] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant Sous Rente] - [Reduced_T_Rappro_N - 1].[Montant Sous Rente]
)/ [Reduced_T_Rappro_N - 1].[Montant Sous Rente]
)
)* 100 AS [ "Evolution montant sous rente" ],
Reduced_T_Rappro_N.[Montant rente initial] AS Montant_Rente_Initial_N,
[Reduced_T_Rappro_N - 1].[Montant rente initial] AS [ "Montant_Rente_Initial_N-1" ],
(
IIf(
[Reduced_T_Rappro_N - 1].[Montant rente initial] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant rente initial] - [Reduced_T_Rappro_N - 1].[Montant rente initial]
)/ [Reduced_T_Rappro_N - 1].[Montant rente initial]
)
)* 100 AS [ "Evolution rente initial" ],
MAX(
[Reduced_T_Rappro_N - 1].[Montant Sous Rente] + [Reduced_T_Rappro_N].[Montant Sous Rente]
) AS [ "Addition" ]
FROM
Reduced_T_Rappro_N
INNER JOIN [Reduced_T_Rappro_N - 1] ON (
Reduced_T_Rappro_N.[Rente RES] = [Reduced_T_Rappro_N - 1].[Rente RES]
)
AND (
Reduced_T_Rappro_N.[Société] = [Reduced_T_Rappro_N - 1].[Société]
)
GROUP BY
Reduced_T_Rappro_N.[Rente RES],
Reduced_T_Rappro_N.[Montant capital constitutif],
[Reduced_T_Rappro_N - 1].[Montant capital constitutif],
[Reduced_T_Rappro_N].[Montant Sous Rente],
[Reduced_T_Rappro_N - 1].[Montant Sous Rente],
Reduced_T_Rappro_N.[Montant rente initial],
[Reduced_T_Rappro_N - 1].[Montant rente initial];
我查询中的划分对应于百分比进化的计算,此外我使用 MS ACCESS 从那里调用方法 iif
结果:
Rente_RES
Montant_Capital_Consitutif_N
Montant_Capital_Consitutif_N-1
Evolution capital constitutif
Montant Sous Rente
Montant Sous Rente N-1
Evolution montant sous rente
Montant Rente Initial N
Montant Rente initial N-1
Evolution rente initial
Addition
00000002-01
0
0
0
200,34
198,35
1,00327703554324
195,61
195,61
0
398,69
00000002-01
0
0
0
200,34
200,34
0
195,61
195,61
0
400,68
00000002-01
0
0
0
202,34
198,35
2,0115956642299
195,61
195,61
0
400,68
00000002-01
0
0
0
202,34
200,34
0,998302885095338
195,61
195,61
0
402,68
00000002-03
25070,68
25070,68
0
1583,2
1583,2
0
1472,18
1472,18
0
3166,4
00000003-04
0
0
0
1358,5
1340,93
1,31028465318845
1266,7
1266,7
0
2699,43
00000003-04
0
0
0
1358,5
1358,5
0
1266,7
1266,7
0
2717
我想要的:
[Montant sous rente N] 和 [Montant sous rente N-1] 之间的加法最大值对应的每个 ID (Rente RES) 只获得一个结果。
Rente_RES
Montant_Capital_Consitutif_N
Montant_Capital_Consitutif_N-1
Evolution capital constitutif
Montant Sous Rente
Montant Sous Rente N-1
Evolution montant sous rente
Montant Rente Initial N
Montant Rente initial N-1
Evolution rente initial
Addition
00000002-01
0
0
0
202,34
200,34
0,998302885095338
195,61
195,61
0
402,68
00000002-03
25070,68
25070,68
0
1583,2
1583,2
0
1472,18
1472,18
0
3166,4
00000003-04
0
0
0
1358,5
1358,5
0
1266,7
1266,7
0
2717
SELECT Reduced_T_Rappro_N.Rente_RES, Max(([Montant_Capital_Consitutif_N-1]+[Montant_Capital_Consitutif_N])) 作为加法
来自 Reduced_T_Rappro_N
分组 Reduced_T_Rappro_N.Rente_RES;
我是 sql 的初学者,我想知道如何为两个连接表的每个 id 获取几个整数的最大值?
到目前为止我做了什么:
SELECT
Reduced_T_Rappro_N.[Rente RES] AS Rente_RES,
Reduced_T_Rappro_N.[Montant capital constitutif] AS Montant_Capital_Consitutif_N,
[Reduced_T_Rappro_N - 1].[Montant capital constitutif] AS [ "Montant_Capital_Constitutif_N-1" ],
IIf(
[Reduced_T_Rappro_N - 1].[Montant capital constitutif] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant capital constitutif] - [Reduced_T_Rappro_N - 1].[Montant capital constitutif]
)/ [Reduced_T_Rappro_N - 1].[Montant capital constitutif]
)* 100 AS [ "Evolution capital constitutif" ],
[Reduced_T_Rappro_N].[Montant Sous Rente],
[Reduced_T_Rappro_N - 1].[Montant Sous Rente],
(
IIf(
[Reduced_T_Rappro_N - 1].[Montant Sous Rente] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant Sous Rente] - [Reduced_T_Rappro_N - 1].[Montant Sous Rente]
)/ [Reduced_T_Rappro_N - 1].[Montant Sous Rente]
)
)* 100 AS [ "Evolution montant sous rente" ],
Reduced_T_Rappro_N.[Montant rente initial] AS Montant_Rente_Initial_N,
[Reduced_T_Rappro_N - 1].[Montant rente initial] AS [ "Montant_Rente_Initial_N-1" ],
(
IIf(
[Reduced_T_Rappro_N - 1].[Montant rente initial] = 0,
0,
(
[Reduced_T_Rappro_N].[Montant rente initial] - [Reduced_T_Rappro_N - 1].[Montant rente initial]
)/ [Reduced_T_Rappro_N - 1].[Montant rente initial]
)
)* 100 AS [ "Evolution rente initial" ],
MAX(
[Reduced_T_Rappro_N - 1].[Montant Sous Rente] + [Reduced_T_Rappro_N].[Montant Sous Rente]
) AS [ "Addition" ]
FROM
Reduced_T_Rappro_N
INNER JOIN [Reduced_T_Rappro_N - 1] ON (
Reduced_T_Rappro_N.[Rente RES] = [Reduced_T_Rappro_N - 1].[Rente RES]
)
AND (
Reduced_T_Rappro_N.[Société] = [Reduced_T_Rappro_N - 1].[Société]
)
GROUP BY
Reduced_T_Rappro_N.[Rente RES],
Reduced_T_Rappro_N.[Montant capital constitutif],
[Reduced_T_Rappro_N - 1].[Montant capital constitutif],
[Reduced_T_Rappro_N].[Montant Sous Rente],
[Reduced_T_Rappro_N - 1].[Montant Sous Rente],
Reduced_T_Rappro_N.[Montant rente initial],
[Reduced_T_Rappro_N - 1].[Montant rente initial];
我查询中的划分对应于百分比进化的计算,此外我使用 MS ACCESS 从那里调用方法 iif
结果:
Rente_RES | Montant_Capital_Consitutif_N | Montant_Capital_Consitutif_N-1 | Evolution capital constitutif | Montant Sous Rente | Montant Sous Rente N-1 | Evolution montant sous rente | Montant Rente Initial N | Montant Rente initial N-1 | Evolution rente initial | Addition |
---|---|---|---|---|---|---|---|---|---|---|
00000002-01 | 0 | 0 | 0 | 200,34 | 198,35 | 1,00327703554324 | 195,61 | 195,61 | 0 | 398,69 |
00000002-01 | 0 | 0 | 0 | 200,34 | 200,34 | 0 | 195,61 | 195,61 | 0 | 400,68 |
00000002-01 | 0 | 0 | 0 | 202,34 | 198,35 | 2,0115956642299 | 195,61 | 195,61 | 0 | 400,68 |
00000002-01 | 0 | 0 | 0 | 202,34 | 200,34 | 0,998302885095338 | 195,61 | 195,61 | 0 | 402,68 |
00000002-03 | 25070,68 | 25070,68 | 0 | 1583,2 | 1583,2 | 0 | 1472,18 | 1472,18 | 0 | 3166,4 |
00000003-04 | 0 | 0 | 0 | 1358,5 | 1340,93 | 1,31028465318845 | 1266,7 | 1266,7 | 0 | 2699,43 |
00000003-04 | 0 | 0 | 0 | 1358,5 | 1358,5 | 0 | 1266,7 | 1266,7 | 0 | 2717 |
我想要的: [Montant sous rente N] 和 [Montant sous rente N-1] 之间的加法最大值对应的每个 ID (Rente RES) 只获得一个结果。
Rente_RES | Montant_Capital_Consitutif_N | Montant_Capital_Consitutif_N-1 | Evolution capital constitutif | Montant Sous Rente | Montant Sous Rente N-1 | Evolution montant sous rente | Montant Rente Initial N | Montant Rente initial N-1 | Evolution rente initial | Addition |
---|---|---|---|---|---|---|---|---|---|---|
00000002-01 | 0 | 0 | 0 | 202,34 | 200,34 | 0,998302885095338 | 195,61 | 195,61 | 0 | 402,68 |
00000002-03 | 25070,68 | 25070,68 | 0 | 1583,2 | 1583,2 | 0 | 1472,18 | 1472,18 | 0 | 3166,4 |
00000003-04 | 0 | 0 | 0 | 1358,5 | 1358,5 | 0 | 1266,7 | 1266,7 | 0 | 2717 |
SELECT Reduced_T_Rappro_N.Rente_RES, Max(([Montant_Capital_Consitutif_N-1]+[Montant_Capital_Consitutif_N])) 作为加法 来自 Reduced_T_Rappro_N 分组 Reduced_T_Rappro_N.Rente_RES;