0

I have a question very similar to this one, but different (aka, I couldn't extend the answer to that one to fit my purposes. Due to the second WHERE condition, specifically).

I have a table which tracks the visit number for customers. There are two types of visits:

| ID | InStoreVisit | InStoreDate | OnlineVisit | OnlineDate |
|----|--------------|-------------|-------------|------------|
| 1  | 1            | 1/1/11      |             |            |
| 1  | 2            | 1/2/11      |             |            |
| 1  |              |             | 1           | 1/3/11     |
| 1  | 3            | 1/4/11      |             |            |
| 2  |              |             | 1           | 2/2/12     |
| 2  | 1            | 2/3/12      |             |            |
| 2  |              |             | 2           | 2/4/12     |

I need to create a new column which has a sort of 'global visit number' as such:

| ID | InStoreVisit | InStoreDate | OnlineVisit | OnlineDate | GobalVisit |
|----|--------------|-------------|-------------|------------|------------|
| 1  | 1            | 1/1/11      |             |            | 1          |
| 1  | 2            | 1/2/11      |             |            | 2          |
| 1  |              |             | 1           | 1/3/11     | 3          |
| 1  | 3            | 1/4/11      |             |            | 4          |
| 2  |              |             | 1           | 2/2/12     | 1          |
| 2  | 1            | 2/3/12      |             |            | 2          |
| 2  |              |             | 2           | 2/4/12     | 3          |

I'm getting mixed up on the WHERE condition with which I can do the self-join. Any advice greatly appreciated.

Community
  • 1
  • 1
Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89

0 Answers0