Error number: 3591; Symbol: ER_WINDOW_DUPLICATE_NAME; SQLSTATE: HY000
Message: Window ‘%s’ is defined twice.
错误说明:
ER_WINDOW_DUPLICATE_NAME意味着窗口重复名称错误。该错误指示给定的名称在重叠窗口定义中已使用。 MySQL中的重叠窗口允许以更新的信息流形式查看数据,以分析数据。
下面给出一个根据某家超市全国消费情况进行数据分析例子,演示ER_WINDOW_DUPLICATE_NAME错误:
SELECT region, product, quantity,
SUM (quantity) OVER (PARTITION BY region ORDER BY product) AS total_quantity
FROM shipment_table
WINDOW shipment_by_region (PARTITION BY region ORDER BY product) AS shipment_by_region
WHERE quantity > 0;
此时,尝试运行以上查询时,MySQL会抛出错误:
Error Number: 3591; Symbol: ER_WINDOW_DUPLICATE_NAME; SQLSTATE: HY000
解决方法:
解决ER_WINDOW_DUPLICATE_NAME错误的最佳方法是从SQL查询中删除重复的窗口定义:
SELECT region, product, quantity,
SUM (quantity) OVER (PARTITION BY region ORDER BY product) AS total_quantity
FROM shipment_table
WHERE quantity > 0;
重新运行以上查询即可解决错误。