我正在尝试计算不同日期范围内的不同实体数量。val distinct_daily_cust_12month = sqlContext.sql(s"select distinct day_id,txn_type,customer_id from ${db_name}.fact_customer where day_id>='${start_last_12month}' and day_id<='${start_date}' and txn_type not in (6,99)")
val c
我有一个产品表,我正在尝试获取每个特定项目的最新价格。我想出了下面的查询,但我觉得它太慢了,因为它太简单了。该表有32,000条记录,这需要908ms才能完成。感觉我错过了一些简单的东西。 SELECT DISTINCT ON (itemsPrices.id) itemsPrices.id, FROM itemsPrices
ORDER BY itemsPrices.id, itemsPrices.timestamp DESC
我查看了Postgres查询计划,注意到上一步开始时间与下一步结束时间没有重叠,所以我想知道间隔时间是在哪里度过的?正如您在下面看到的,查询执行程序有两个步骤。postgres 9.1from report A where------------------------------------------------------------------------------------