Author |
Topic |
bmsra79
Starting Member
24 Posts |
Posted - 2012-10-31 : 14:50:16
|
I have 3 Views:View1: Country, State, Category1, Category2, Year, Quarter, Total_SalesView2: Country, City, Category1, Category2, Year, Quarter, Total_PopView3: City, State, CountrySince the Views by themselves are aggregated queries, I want the most efficient way to combine all the 3 views.Required o/p:Country, State, Category1, Category2, Year, Quarter, Total_Sales, Total_Pop |
|
bmsra79
Starting Member
24 Posts |
Posted - 2012-10-31 : 15:01:28
|
Sample Values:View1: United States, MA, Books, Publications, 2012, 2, 1500View2: United States, Boston, Books, Publications, 2012, 2, 200000View3: MA, Boston, United StatesIssues:- Few STATE entries in View1 not having corresponding CITY records in View2- Few CITY records in View2 not having entries for STATE in View1 |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-10-31 : 15:50:54
|
It sounds like it mught be easier to just ignore the views and write a new query. I beleive it is going to be difficult/impossible to get the results you want based on the inability to join the views at the lowet grain (city) you want. But, perhaps I do not undersant the data well enough. It might help if you supply sample data and expected output, but I took a rough stab at a query that might help you: SELECT View3.Country, View3.State, View2.Category1, View2.Category2, View2.Year, View2.Quarter, View.1Total_Sales, View2.Total_PopFROM View3INNER JOIN View2 ON View3.Country = View2.Country AND View3.City = View2.CityINNER JOIN View1 ON View3.Country = View1.Country AND View3.City = View1.State AND View2.Category1 = View1.Category1 AND View2.Category2 = View1.Category2 |
 |
|
|
|
|