sql - Identifying Unique Visits by Customer -



sql - Identifying Unique Visits by Customer -

i'm working in sql server , have table of customerid, visitdate, sales, , quantity. i'm trying calculate average check visit, how much client purchase on his/her first repeat purchase, 2nd repeat purchase, etc. also, how much time passes between each purchase.

any guidance helpful, thanks!

you can utilize row_number() , conditional aggregation. here exaple:

select customerid, avg(sales) avgsales, max(case when segnum = 1 sales end) sales_01, max(case when segnum = 2 sales end) sales_02, max(case when segnum = 3 sales end) sales_03 (select t.*, row_number() on (partition customerid order visitdate) segnum table t ) t grouping customerid;

by way, question should include sample data, desired results, , table layout,

sql sql-server

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -