By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| OrdID | Cat | Qty | City | Ctry |
|---|---|---|---|---|
| 1 | TV | 5 | London | England |
| 2 | Laptop | 3 | London | England |
| 3 | Laptop | 4 | Berlin | Germany |
| CustID | CustType | City | NumItems |
|---|---|---|---|
| 1 | New | London | 2 |
| 2 | Returning | London | 5 |
| 3 | Returning | Berlin | 2 |
| 4 | New | Berlin | 8 |
| Cat | Qty | City | Country | NewC | RetCust | TotC |
|---|---|---|---|---|---|---|
| Laptop | 4 | Berlin | Germany | 8 | 2 | 10 |
| Laptop | 3 | London | England | 2 | 5 | 7 |
| TV | 5 | London | England | 2 | 5 | 7 |
| Cat | Qty | City | Ctry | RetC | TotC |
|---|---|---|---|---|---|
| Laptop | 3 | London | England | null | 2 |
| Laptop | 3 | London | England | 5 | 5 |
| Laptop | 4 | Berlin | Germany | null | 8 |
| Laptop | 4 | Berlin | Germany | 2 | 2 |
| TV | 5 | London | England | null | 2 |
| TV | 5 | London | England | 5 | 5 |