Alex A
asked on
SQL query, getting number of days from first record
How would you write a query to get Customer Id, VisitDate, NumberOfDaysFromFirstVisit from the tables below?
Customer
Id Name
101 Name1
102 Name2
103 Name3
… …
CustomerVisit
Id VisitDate VisitedCity
101 1/1/2017 City1
101 1/5/2016 City2
101 1/3/2016 City3
102 1/1/2016 City1
102 1/5/2016 City2
102 1/3/2016 City1
102 1/1/2016 City2
103 1/1/2017 City1
104 1/1/2017 City2
105 1/1/2017 City4
... ... ...
Thank you in advance.
Customer
Id Name
101 Name1
102 Name2
103 Name3
… …
CustomerVisit
Id VisitDate VisitedCity
101 1/1/2017 City1
101 1/5/2016 City2
101 1/3/2016 City3
102 1/1/2016 City1
102 1/5/2016 City2
102 1/3/2016 City1
102 1/1/2016 City2
103 1/1/2017 City1
104 1/1/2017 City2
105 1/1/2017 City4
... ... ...
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.