Oracle 与 MariaDB 的分析功能
Analytical Function Of Oracle vs MariaDB
目前正在将我的 Oracle 查询迁移到 MariaDB 10.4
我在解析函数上很吃力
MARIADB Code:
select cgi, timestamp, hour, rat_type, dl_tput,
ntile(24) over (partition by timestamp,rat_type order by dl_tput) as dl_tput_ntiled
from (select cgi, date(timestamp) as timestamp,
date_format(timestamp,'%H') as hour, rat_type, avg(avg_mean_down) as dl_tput
from JUST_TEST_A
where avg_mean_down is not null
group by cgi, date(timestamp),date_format(timestamp,'%H'),rat_type
) x ;
此代码工作正常,但在验证输出后,Oracle 的结果与 MariaDB 的结果不同(相同数据)
我的 oracle 脚本有我在 mariadb 中删除的这个脚本。
select cgi, timestamp, hour, rat_type, dl_tput,
ntile(24) over (partition by timestamp,rat_type order by dl_tput) as dl_tput_ntiled,
count(*) over () as dl_tput_cnt
from (...)
count(*) over ()
会影响我的输出吗? MariaDB这个解析函数的替代查询是什么?
我怀疑这是领带的问题。 ntile()
会将具有相同组的行拆分到不同的存储桶中,因为它要求每个存储桶的大小相同。
作为一个极端的例子,如果dl_tput
的所有值都相同,那么可以分配1到24的任何值。
在此演示中:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=be74a9fa9059d6b80a8cb10d102355d4
你会发现一个小例子,我输入了一些数据并且有一个查询:
select pk
, a
, b
, ntile(24) over (partition by a, b order by pk)
, count(*) over () as dl_tput_cnt
from t1;
在左上角有一个不同数据库的列表,您可以从中进行选择。如果您为此示例选择 Oracle,或者如果您选择 Maria DB,结果将是相同的。这不能保证 count
和 ntile
不对您的不同结果负责,但请告诉我们更多关于此结果的信息:
but after validating the output the result from Oracle is different
from the result of MariaDB (same data)
也许这对您的情况会有更多帮助。
还有一件事。
我认为您应该检查从 Maria DB 获得的查询结果:
SELECT date(timestamp) FROM JUST_TEST_A
SELECT date_format(timestamp,'%H') FROM JUST_TEST_A
并将它们与您从 Oracle 收到的关于日期和 date_format 的 Oracle 等效函数的旧结果进行比较。
目前正在将我的 Oracle 查询迁移到 MariaDB 10.4
我在解析函数上很吃力
MARIADB Code:
select cgi, timestamp, hour, rat_type, dl_tput,
ntile(24) over (partition by timestamp,rat_type order by dl_tput) as dl_tput_ntiled
from (select cgi, date(timestamp) as timestamp,
date_format(timestamp,'%H') as hour, rat_type, avg(avg_mean_down) as dl_tput
from JUST_TEST_A
where avg_mean_down is not null
group by cgi, date(timestamp),date_format(timestamp,'%H'),rat_type
) x ;
此代码工作正常,但在验证输出后,Oracle 的结果与 MariaDB 的结果不同(相同数据)
我的 oracle 脚本有我在 mariadb 中删除的这个脚本。
select cgi, timestamp, hour, rat_type, dl_tput,
ntile(24) over (partition by timestamp,rat_type order by dl_tput) as dl_tput_ntiled,
count(*) over () as dl_tput_cnt
from (...)
count(*) over ()
会影响我的输出吗? MariaDB这个解析函数的替代查询是什么?
我怀疑这是领带的问题。 ntile()
会将具有相同组的行拆分到不同的存储桶中,因为它要求每个存储桶的大小相同。
作为一个极端的例子,如果dl_tput
的所有值都相同,那么可以分配1到24的任何值。
在此演示中:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=be74a9fa9059d6b80a8cb10d102355d4
你会发现一个小例子,我输入了一些数据并且有一个查询:
select pk
, a
, b
, ntile(24) over (partition by a, b order by pk)
, count(*) over () as dl_tput_cnt
from t1;
在左上角有一个不同数据库的列表,您可以从中进行选择。如果您为此示例选择 Oracle,或者如果您选择 Maria DB,结果将是相同的。这不能保证 count
和 ntile
不对您的不同结果负责,但请告诉我们更多关于此结果的信息:
but after validating the output the result from Oracle is different from the result of MariaDB (same data)
也许这对您的情况会有更多帮助。
还有一件事。
我认为您应该检查从 Maria DB 获得的查询结果:
SELECT date(timestamp) FROM JUST_TEST_A
SELECT date_format(timestamp,'%H') FROM JUST_TEST_A
并将它们与您从 Oracle 收到的关于日期和 date_format 的 Oracle 等效函数的旧结果进行比较。