|
|
|
|
|
by fifilura
1755 days ago
|
|
There are lots of cases where a join with yourself is applicable, although they are mostly superseded by window functions these days. For example normalisation (join with a groupby/sum of yourself) or rank (join each row with all rows that have lower value than yourself and count those rows). But as I mentioned above. A good start is to sketch that out in excel. You will realize that what you need is another column (e.g. total sum for this id). And from that you can work yourself backwards to figure out what is the table you need to join with to create that column. |
|
the question was: "List all pairs of customer IDs who live on a street with the same name but in a different city." listed under self-join
that said i haven't wrangled with raw sql in a spell so the reading on window functions is interesting.