[英]SQL: Workaround for the maximum expression limit
I am trying to perform some basic customer segmentation/profile analysis on a set of 4000 accounts. 我正在尝试对4000个帐户进行一些基本的客户细分/配置文件分析。
I'd like to do a quick customer segmentation based on usage and tenure. 我想根据使用情况和使用期限对客户进行快速细分 。 Tactically, this means querying an Oracle SQL database for Acocunt_IDs that meet certain criteria. 从策略上讲,这意味着在Oracle SQL数据库中查询符合特定条件的Acocunt_ID。
For example, the usage query will return the subset of accounts that have more than > 100 hours of usage over the last month. 例如,使用情况查询将返回在过去一个月中使用时间超过100小时的帐户子集。
Once I have this list of accounts, I'd like ask a different set of profiling questions. 拥有此帐户列表后,我想提出一组不同的配置问题。
For example, for the customers that had more than 100 hours of usage: what products did they use? 例如,对于有超过100个小时的使用时间的客户:他们使用什么样的产品? how long have they been a customer? 他们成为客户多长时间了? what was the referral source? 推荐来源是什么?
My basic approach has been: 我的基本方法是:
Run the Profile queries for each of the customer segments, using the structure below: 使用以下结构为每个客户群运行概要文件查询:
Select * From fooo where Account_ID in ('00001','00002','00003')
The challenge is that the customer segment queries return more than 1000 results, so i have to manually substitute in different batches of account_IDs in sets of 1000. This is required because of Oracle SQL's 1,000 expression limit. 挑战在于,客户群查询返回的结果超过1000个,因此我必须手动替换1000个集合中不同批次的account_IDs。这是必需的,因为Oracle SQL的表达式限制为1000个。
The alternative would be to combine the customer segment queries in the profile queries, but this makes the queries take a ages to execute. 另一种选择是将客户细分查询与概要文件查询组合在一起,但这会使查询需要一定的执行时间。
SO. 所以。 The question is there an efficient way to create and populate a temporary table in Oracle SQL that I can use to dump the customer segment query results and then throw those results into profile queries to ensure that they run more efficicently? 问题是,有没有一种有效的方法可以在Oracle SQL中创建和填充临时表,我可以使用该表来转储客户群查询结果,然后将这些结果放入概要文件查询中,以确保它们更有效地运行?
Would using the ROW_NUMBER() window aggregate function to assign a RowID based on the ASCENDING order of the AccountID then use a WHERE clause to process n number of rows be acceptable: 将使用ROW_NUMBER()窗口聚合函数根据AccountID的ASCENDING顺序分配RowID,然后使用WHERE子句处理n个可接受的行:
SELECT DT1.*
FROM (SELECT f1.*
, ROW_NUMBER() OVER (ORDER BY F1.AccountID) AS RowID_
FROM foo f1
) DT1
WHERE DT1.RowID_ BETWEEN 1 and /* n */
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.