我在x86_64使用mysql 版本8.0.3-RC爲Linux(MySQL社區服務器(GPL))MySQL的8個窗口功能+全文搜索
列上創建表和全文索引名
CREATE TABLE `title` (
`id` smallint(4) unsigned NOT NULL PRIMARY KEY,
`name` text COLLATE utf8_unicode_ci,
FULLTEXT idx (name) WITH PARSER ngram
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
插入一些數據:
insert into `title` values(14,"I'm flying in for the game (one night in Niagara Falls, NY and one night in Buffalo then back home).");
insert into `title` values(23,"I've never been to the area.");
insert into `title` values(43,"Where and what must I eat (Canadian side of Niagara, American side and Buffalo)?");
insert into `title` values(125,"Don't really have much planned other than the Falls and the game.");
當執行:
select
id,
round(MATCH (name) AGAINST ('other than the'),2) scope
from title;
結果(一切OK):
id | scope
----------
14 | 0.43
23 | 0.23
43 | 0.12
125 | 1.15
當使用經典GROUP BY - 一切ok
select
max(scope),
min(scope),
sum(scope)
from
(
select id, round(MATCH (name) AGAINST ('other than the'),2) scope
from title
) a;
結果確定:
max | min | sum
----------------
1.15 | 0.12 | 1.96
但是當我嘗試使用窗口功能在我不明白的結果:
select
id,
max(scope) over(),
min(scope) over(),
sum(scope) over()
from
(
select id, round(MATCH (name) AGAINST ('other than the'),2) scope
from title
) a;
我得到一個奇怪的結果(爲什麼?):
id | max | min | sum
------------------------
14 | 1.15 | 1.15 | 4.60
23 | 1.15 | 1.15 | 4.60
43 | 1.15 | 1.15 | 4.60
125| 1.15 | 1.15 | 4.60
我希望通過得到類似古典組的結果,如:
id | max | min | sum
------------------------
14 | 1.15 | 0.12 | 1.96
23 | 1.15 | 0.12 | 1.96
43 | 1.15 | 0.12 | 1.96
125| 1.15 | 0.12 | 1.96
這是在MySQL 版本8.0.3-RC或不正確我查詢了錯誤? 謝謝!
你的結果對我來說似乎很陌生。我也希望你能得到相同的輸出。 –
你的觀察是正確的。這是8.0.3-rc發佈後修復的錯誤。 -Dag(MySQL dev) – DagW