Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7afc3eae
Unverified
提交
7afc3eae
authored
6 年前
作者:
Evgenij Ryazanov
提交者:
GitHub
6 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1486 from katzyn/window
Fix window frame problems
上级
04415644
b5e7b9d0
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
138 行增加
和
58 行删除
+138
-58
changelog.html
h2/src/docsrc/html/changelog.html
+10
-0
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+28
-26
Window.java
h2/src/main/org/h2/expression/aggregate/Window.java
+1
-1
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+25
-17
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+3
-4
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+40
-0
count.sql
...rc/test/org/h2/test/scripts/functions/aggregate/count.sql
+10
-0
nth_value.sql
...c/test/org/h2/test/scripts/functions/window/nth_value.sql
+21
-10
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
7afc3eae
...
@@ -21,8 +21,18 @@ Change Log
...
@@ -21,8 +21,18 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul>
<ul>
<li>
Issue #1485: Default window frame in presence of ORDER BY is RANGE .., not ROWS
</li>
<li>
PR #1484: New tests, reimplemented EXCLUDE clause, and assorted changes
</li>
<li>
Issue #1338: MSSQLServer compatibility enhancements
<li>
Issue #1338: MSSQLServer compatibility enhancements
</li>
</li>
<li>
PR #1480: Update Maven build instruction and fix some problems
</li>
<li>
PR #1478: Upgrade maven-surefire-plugin
</li>
<li>
PR #1476: Add TransactionStore to MVStore jar
</li>
<li>
Issue #1475: Dropping column used by a view produces misleading error message
<li>
Issue #1475: Dropping column used by a view produces misleading error message
</li>
</li>
<li>
Issue #1473: TestScript needs better detection of sorted result
<li>
Issue #1473: TestScript needs better detection of sorted result
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
7afc3eae
...
@@ -75,36 +75,38 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -75,36 +75,38 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
protected
void
getOrderedResultLoop
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
protected
void
getOrderedResultLoop
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
rowIdColumn
)
{
WindowFrame
frame
=
over
.
getWindowFrame
();
WindowFrame
frame
=
over
.
getWindowFrame
();
if
(
frame
==
null
||
frame
.
isDefault
())
{
if
(
frame
==
null
)
{
// Aggregate all values before the current row (including)
if
(
over
.
getOrderBy
()
==
null
)
{
Object
aggregateData
=
createAggregateData
();
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
for
(
Value
[]
row
:
ordered
)
{
return
;
// Collect values one by one
updateFromExpressions
(
session
,
aggregateData
,
row
);
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
));
}
}
}
else
if
(
frame
.
isFullPartition
())
{
}
else
if
(
frame
.
isFullPartition
())
{
// Aggregate values from the whole partition
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
return
;
}
// All other types of frames (slow)
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
for
(
Value
[]
row
:
ordered
)
{
for
(
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
updateFromExpressions
(
session
,
aggregateData
,
row
);
false
);
iter
.
hasNext
();)
{
}
updateFromExpressions
(
session
,
aggregateData
,
iter
.
next
());
// All rows have the same value
Value
value
=
getAggregatedValue
(
session
,
aggregateData
);
for
(
Value
[]
row
:
ordered
)
{
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
value
);
}
}
else
{
// All other types of frames (slow)
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Object
aggregateData
=
createAggregateData
();
for
(
Iterator
<
Value
[]>
iter
=
frame
.
iterator
(
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
);
iter
.
hasNext
();)
{
updateFromExpressions
(
session
,
aggregateData
,
iter
.
next
());
}
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
));
}
}
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
));
}
}
private
void
aggregateWholePartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
// Aggregate values from the whole partition
Object
aggregateData
=
createAggregateData
();
for
(
Value
[]
row
:
ordered
)
{
updateFromExpressions
(
session
,
aggregateData
,
row
);
}
// All rows have the same value
Value
value
=
getAggregatedValue
(
session
,
aggregateData
);
for
(
Value
[]
row
:
ordered
)
{
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
value
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
7afc3eae
...
@@ -224,7 +224,7 @@ public final class Window {
...
@@ -224,7 +224,7 @@ public final class Window {
}
}
}
}
appendOrderBy
(
builder
,
orderBy
);
appendOrderBy
(
builder
,
orderBy
);
if
(
frame
!=
null
&&
!
frame
.
isDefault
()
)
{
if
(
frame
!=
null
)
{
if
(
builder
.
charAt
(
builder
.
length
()
-
1
)
!=
'('
)
{
if
(
builder
.
charAt
(
builder
.
length
()
-
1
)
!=
'('
)
{
builder
.
append
(
' '
);
builder
.
append
(
' '
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
7afc3eae
...
@@ -192,8 +192,8 @@ public final class WindowFrame {
...
@@ -192,8 +192,8 @@ public final class WindowFrame {
* Returns iterator for the specified frame, or default iterator if frame is
* Returns iterator for the specified frame, or default iterator if frame is
* null.
* null.
*
*
* @param
frame
* @param
over
* window
frame, or null
* window
* @param session
* @param session
* the session
* the session
* @param orderedRows
* @param orderedRows
...
@@ -207,10 +207,16 @@ public final class WindowFrame {
...
@@ -207,10 +207,16 @@ public final class WindowFrame {
*
*
* @return iterator
* @return iterator
*/
*/
public
static
Iterator
<
Value
[]>
iterator
(
Window
Frame
frame
,
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
public
static
Iterator
<
Value
[]>
iterator
(
Window
over
,
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
boolean
reverse
)
{
SortOrder
sortOrder
,
int
currentRow
,
boolean
reverse
)
{
return
frame
!=
null
?
frame
.
iterator
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
reverse
)
WindowFrame
frame
=
over
.
getWindowFrame
();
:
plainIterator
(
orderedRows
,
0
,
currentRow
,
reverse
);
if
(
frame
!=
null
)
{
return
frame
.
iterator
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
reverse
);
}
int
endIndex
=
orderedRows
.
size
()
-
1
;
return
plainIterator
(
orderedRows
,
0
,
over
.
getOrderBy
()
==
null
?
endIndex
:
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
endIndex
),
reverse
);
}
}
private
static
Iterator
<
Value
[]>
plainIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
,
private
static
Iterator
<
Value
[]>
plainIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
,
...
@@ -314,16 +320,6 @@ public final class WindowFrame {
...
@@ -314,16 +320,6 @@ public final class WindowFrame {
&&
s
.
compareTo
(
f
)
<=
0
;
&&
s
.
compareTo
(
f
)
<=
0
;
}
}
/**
* Returns whether window frame specification can be omitted.
*
* @return whether window frame specification can be omitted
*/
public
boolean
isDefault
()
{
return
starting
.
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_PRECEDING
&&
following
==
null
&&
exclusion
==
WindowFrameExclusion
.
EXCLUDE_NO_OTHERS
;
}
/**
/**
* Returns whether window frame specification contains all rows in
* Returns whether window frame specification contains all rows in
* partition.
* partition.
...
@@ -356,7 +352,8 @@ public final class WindowFrame {
...
@@ -356,7 +352,8 @@ public final class WindowFrame {
int
currentRow
,
boolean
reverse
)
{
int
currentRow
,
boolean
reverse
)
{
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
,
false
);
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
,
false
);
int
endIndex
=
following
!=
null
?
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
following
,
true
)
int
endIndex
=
following
!=
null
?
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
following
,
true
)
:
currentRow
;
:
units
==
WindowFrameUnits
.
ROWS
?
currentRow
:
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
orderedRows
.
size
()
-
1
);
if
(
endIndex
<
startIndex
)
{
if
(
endIndex
<
startIndex
)
{
return
Collections
.
emptyIterator
();
return
Collections
.
emptyIterator
();
}
}
...
@@ -446,7 +443,18 @@ public final class WindowFrame {
...
@@ -446,7 +443,18 @@ public final class WindowFrame {
}
}
break
;
break
;
case
CURRENT_ROW:
case
CURRENT_ROW:
index
=
currentRow
;
switch
(
units
)
{
case
ROWS:
index
=
currentRow
;
break
;
case
GROUPS:
case
RANGE:
index
=
forFollowing
?
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
last
)
:
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
0
);
break
;
default
:
throw
DbException
.
getUnsupportedException
(
"units="
+
units
);
}
break
;
break
;
case
FOLLOWING:
case
FOLLOWING:
switch
(
units
)
{
switch
(
units
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
7afc3eae
...
@@ -345,17 +345,16 @@ public class WindowFunction extends DataAnalysisOperation {
...
@@ -345,17 +345,16 @@ public class WindowFunction extends DataAnalysisOperation {
private
void
getNth
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
private
void
getNth
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
size
=
ordered
.
size
();
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
WindowFrame
frame
=
over
.
getWindowFrame
();
Value
[]
row
=
ordered
.
get
(
i
);
Value
[]
row
=
ordered
.
get
(
i
);
int
rowId
=
row
[
rowIdColumn
].
getInt
();
int
rowId
=
row
[
rowIdColumn
].
getInt
();
Value
v
;
Value
v
;
switch
(
type
)
{
switch
(
type
)
{
case
FIRST_VALUE:
case
FIRST_VALUE:
v
=
getNthValue
(
WindowFrame
.
iterator
(
frame
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
),
0
,
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
),
0
,
ignoreNulls
);
ignoreNulls
);
break
;
break
;
case
LAST_VALUE:
case
LAST_VALUE:
v
=
getNthValue
(
WindowFrame
.
iterator
(
frame
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
true
),
0
,
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
true
),
0
,
ignoreNulls
);
ignoreNulls
);
break
;
break
;
case
NTH_VALUE:
{
case
NTH_VALUE:
{
...
@@ -364,7 +363,7 @@ public class WindowFunction extends DataAnalysisOperation {
...
@@ -364,7 +363,7 @@ public class WindowFunction extends DataAnalysisOperation {
throw
DbException
.
getInvalidValueException
(
"nth row"
,
n
);
throw
DbException
.
getInvalidValueException
(
"nth row"
,
n
);
}
}
n
--;
n
--;
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
frame
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
fromLast
);
fromLast
);
v
=
getNthValue
(
iter
,
n
,
ignoreNulls
);
v
=
getNthValue
(
iter
,
n
,
ignoreNulls
);
break
;
break
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
7afc3eae
...
@@ -449,6 +449,26 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 2 PRECEDING A
...
@@ -449,6 +449,26 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 2 PRECEDING A
>
8
9
(
4
,
5
,
6
)
>
8
9
(
4
,
5
,
6
)
>
rows
:
8
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
>
1
1
(
1
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
>
2
1
(
1
,
2
)
(
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
>
3
5
(
1
,
2
,
3
)
(
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
)
(
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
)
(
3
,
4
,
5
,
6
,
7
,
8
)
>
4
8
(
1
,
2
,
3
,
4
)
(
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
>
5
8
(
1
,
2
,
3
,
4
,
5
)
(
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
>
6
8
(
1
,
2
,
3
,
4
,
5
,
6
)
(
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
4
,
5
,
6
,
7
,
8
)
>
7
9
(
1
,
2
,
3
,
4
,
5
,
6
,
7
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
>
8
9
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
>
rows
:
8
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
CURRENT
ROW
AND
1
PRECEDING
)
FROM
TEST
;
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
CURRENT
ROW
AND
1
PRECEDING
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
>
exception
SYNTAX_ERROR_1
...
@@ -523,5 +543,25 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING A
...
@@ -523,5 +543,25 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING A
>
8
4
null
>
8
4
null
>
rows
:
8
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
>
1
1
(
1
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
>
2
1
(
1
,
2
)
(
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
>
3
2
(
1
,
2
,
3
)
(
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
)
(
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
)
(
3
,
4
,
5
,
6
,
7
,
8
)
>
4
2
(
1
,
2
,
3
,
4
)
(
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
)
(
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
)
(
3
,
4
,
5
,
6
,
7
,
8
)
>
5
3
(
1
,
2
,
3
,
4
,
5
)
(
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
5
,
6
,
7
,
8
)
>
6
3
(
1
,
2
,
3
,
4
,
5
,
6
)
(
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
5
,
6
,
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
)
(
5
,
6
,
7
,
8
)
>
7
4
(
1
,
2
,
3
,
4
,
5
,
6
,
7
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
>
8
4
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
>
rows
:
8
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/functions/aggregate/count.sql
浏览文件 @
7afc3eae
...
@@ -94,3 +94,13 @@ SELECT I, C, COUNT(I) OVER (PARTITION BY C) CNT FROM
...
@@ -94,3 +94,13 @@ SELECT I, C, COUNT(I) OVER (PARTITION BY C) CNT FROM
>
4
2
3
>
4
2
3
>
5
2
3
>
5
2
3
>
rows
:
5
>
rows
:
5
SELECT
X
,
COUNT
(
*
)
OVER
(
ORDER
BY
X
)
C
FROM
VALUES
(
1
),
(
1
),
(
2
),
(
2
),
(
3
)
V
(
X
);
>
X
C
>
-
-
>
1
2
>
1
2
>
2
4
>
2
4
>
3
5
>
rows
:
5
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/functions/window/nth_value.sql
浏览文件 @
7afc3eae
...
@@ -136,25 +136,26 @@ SELECT *,
...
@@ -136,25 +136,26 @@ SELECT *,
>
rows
(
ordered
):
13
>
rows
(
ordered
):
13
SELECT
ID
,
CATEGORY
,
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
ANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
ANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
EXCLUDE
CURRENT
ROW
)
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
EXCLUDE
CURRENT
ROW
)
FROM
TEST
FETCH
FIRST
3
ROWS
ONLY
;
FROM
TEST
FETCH
FIRST
3
ROWS
ONLY
;
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
ANGE
UNBOUNDED
PRECEDING
EXCLUDE
CURRENT
ROW
)
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
UNBOUNDED
PRECEDING
EXCLUDE
CURRENT
ROW
)
>
-- -------- ---- --------------------------------------------------------------------------------------------
-
>
-- -------- ---- --------------------------------------------------------------------------------------------
>
1
1
null
null
>
1
1
null
null
>
2
1
1
null
>
2
1
1
null
>
3
1
1
1
>
3
1
1
1
>
rows
:
3
>
rows
:
3
SELECT
ID
,
CATEGORY
,
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C2
,
NTH_VALUE
(
CATEGORY
,
3
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C3
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
FROM
TEST
OFFSET
10
ROWS
;
FROM
TEST
OFFSET
10
ROWS
;
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT_ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
>
ID
CATEGORY
C
2
C3
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT_ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
>
-- -------- ---- -------------------------------------------------------------------------------------------------------------------------------
>
-- -------- --
--
-- -------------------------------------------------------------------------------------------------------------------------------
>
11
3
4
4
>
11
3
4
3
4
>
12
4
4
null
>
12
4
4
null
null
>
13
4
null
null
>
13
4
4
null
null
>
rows
:
3
>
rows
:
3
SELECT
ID
,
CATEGORY
,
SELECT
ID
,
CATEGORY
,
...
@@ -219,3 +220,13 @@ SELECT ID, CATEGORY,
...
@@ -219,3 +220,13 @@ SELECT ID, CATEGORY,
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
SELECT
I
,
X
,
LAST_VALUE
(
I
)
OVER
(
ORDER
BY
X
)
L
FROM
VALUES
(
1
,
1
),
(
2
,
1
),
(
3
,
2
),
(
4
,
2
),
(
5
,
3
)
V
(
I
,
X
);
>
I
X
L
>
-
-
-
>
1
1
2
>
2
1
2
>
3
2
4
>
4
2
4
>
5
3
5
>
rows
:
5
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论