Calculate the impact of each record to the “Average Selling Price” in the attached excel file.
Attached excel file? This sounds like homework or someone at the office asking for a very odd request.
For example, If you were to exclude the Aguirre purchase of SKU A in the US, what would be the “Average Selling Price” for A in the US?
Additionally, after itinerating over the 4 transaction for SKU B in the US, what is the ranking of each transaction regarding the impact to the ASP?
These questions are overloaded, but they're also horribly out of context. How do you want to rank the impact? Largest change from the average? Largest or smallest value? There's a lot to decide there. Also, dynamic filtering is usually not simple to do via T-SQL without expectations of how you want to filter. That example isn't specific enough to setup a parameterized request against.
country sku customer units sales unit price Average Selling Price
us a aguirre 10 100 10 15.55555556
us a wirt 100 2000 20
us a emrich 3 50 16.66667
us b aguirre 34 100 2.941176 9.190627744
us b wirt 67 2000 29.85075
us b emrich 34 50 1.470588
us b jory 20 50 2.5
This is not consumable, but semi-useful as an example if you wanted short answers to your questions. The problem is, I'm not sure what the question really is. You've asked us how to use a loop. I can explain that, but I don't know what you want to DO with the loop. Not a single question above requires one... and honestly I don't want to do your homework for you if that's what that is, or puzzle out the business requirement if it's not. Define your problem in consumable format (schema/sample data), show us what you've attempted and *specifically* what you're trying to get it to do (not vague examples) and we'll help you out.
- Craig Farrell
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake. For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally TablesTwitter: @AnyWayDBA