使用row_number()函数超过事实表中的十亿条记录(SQL server 2014) [英] Using row_number() function over a billion records in fact table(SQL server 2014)

查看:188
本文介绍了使用row_number()函数超过事实表中的十亿条记录(SQL server 2014)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含国家代码(例如:AUS,USA),outlet,product,salesrep,audit_date列的列的事实表。



我需要得到根据国家代码,出口,产品和销售额的最新销售点访问。理想情况下,我使用所有列的row_number函数分区,并按audit_date desc排序,只取值行号= 1.



事实表超过了十亿条记录,所以查询花了很多时间。



没有权限在源表上创建新索引。



有没有其他方法可以解决这个问题,或者请我让这个查询运行得更快。



我尝试过的方法:



查询花了很多时间。

I have a fact table with columns like country code(eg:AUS,USA) ,outlet,product,salesrep,audit_date columns.

I need to get the latest outlet visit of a salesrep based on country code ,outlet,product and salesrep. So ideally i am using a row_number function partition by all the columns and order by audit_date desc and taking only values row number=1.

The fact table is having over a billion records and so the query is taking hell lot of time.

There is no permission to create new indexes on the source table.

Is there any alternate approach to this or please me ways of making this query run faster.

What I have tried:

The query is taking a hell lot of time.

推荐答案

使用最大日期和多列组。试试这个:

Use max date and multiple-column group by. Try this:
SELECT country, outlet, product, salesrep, MAX(audit_date) as last_date
FROM table1
GROUP BY country, outlet, product, salesrep


这篇关于使用row_number()函数超过事实表中的十亿条记录(SQL server 2014)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆