这就是我所做的:in case of avg per class
select cust_classes,
avg(InvoiceDate("2017-12-31") - (InvoiceDate)) as
avg_least_days
from tbl
group by cust_classes
它给了0
所以我想也许它是零。因此测试如下:
要查看每位客户的最少访问天数。non avg query as the question
select cust_id,cust_classes,
(InvoiceDate("2017-12-31") - (InvoiceDate)) as
avg_least_days
from tbl
它为所有不正确的人返回0
。
问题是什么? 所需的输出:
cust_id num_days_from_last_visit
1 3
2 12
3 9
答案 0 :(得分:2)
这应该有效,假设visit_date
是表格中的一列:
select t.ethnicity,
avg(julianday('2017-12-31') - julianday(t.visit_date)) as
avg_least_days
from table_1 t
group by t.ethnicity;