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

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -