I have a PriceComparison table with (StoreNumber, ItemNumber, Price) that keeps pricing data for head-to-head comparison shopping. The goal is a recordset with the following things for all stores:
- StoreNumber
- COUNT of head-to-head wins for that store
- COUNT of head-to-head losses for that store
- COUNT of head-to-head ties for that store
- SUM of all item pricing for that store
- SUM of all head-to-head competitor pricing for items above for that store
Example:
StoreNumber ItemNumber Price
----------- ---------- -----
101 1 1.39
102 1 1.89
101 2 3.49
103 2 2.99
101 3 9.99
104 3 9.99
I’m thinking I can calculate these SUMs and COUNTs if I can get a temporary column added for CompetitorPrice. That way, the item has both prices listed, and it becomes easy.
How can I get this information in the correct configuration? I tried an INNER JOIN to the same table, but that gets tricky.
Thanks!
UPDATE: This is for MS SQL Server.
UPDATE: There will only be two prices per item, no more than 2 stores.
1 Answer