【发布时间】:2020-07-04 18:04:24
【问题描述】:
我有一个表“L20”,其中包含 1 到 20 个值“HDIF”,按升序排序。我需要根据表“L20”中值的数量将这些值的前 1 到 10 个提取到表“T10”中。我正在使用带有 Firebird 3 数据库的 Windows 10、Libreoffice 6.4.4。我已经在“L20”中的 COUNT 行上尝试了 CASE 语句和 DECODE 语句,但似乎都不起作用。
如果我在表“L20”上为 SELECT 输入一个数字,那么它可以正常工作。任何人都知道如何解决?此查询的目的是计算一个高尔夫让分盘,它使用 [最多] 最近(最近)20 场比赛的最佳(最低)10 分。下面是代码:
/* Qry_Index_Calc - calculates handicap index from top 10 differentials of last 20 games */
/* Source is "VW_Plyr_Diff" which has handicap differentials already calculated. */
SELECT (AVG ("T10"."HDIF") * .96) "Index", (Count ("T10"."HDIF")) FROM
/* Get only the games needed if less than 20 games have been played. */
(
SELECT FIRST
DECODE ((SELECT COUNT (*) FROM "L20"),
1, 1
, 2, 1
, 3, 1
, 4, 1
, 5, 1
, 6, 1
, 7, 2
, 8, 2
, 9, 3
, 10, 3
, 11, 4
, 12, 4
, 13, 5
, 14, 5
, 15, 6
, 16, 6
, 17, 7
, 18, 8
, 19, 9
, 10)
"L20"."HDIF"
FROM
/* Get up to 20 of the most recent (last) games played. */
( SELECT FIRST 20 "PlayerID" "PID", "GID" "GID",
RANK ( ) OVER ( PARTITION BY "PlayerID" ORDER BY "Diff" ) "Rnk",
"Diff" "HDIF", "Date" "Gdate"
FROM "Vw_Plyr_Diff"
WHERE "PlayerID" = 1)
"L20"
) "T10"
【问题讨论】:
标签: sql select firebird firebird-3.0 libreoffice-base