Question : SQL Question: Multiple tables and Group By

Question: Need some advice on a single sql or sequence of sqls required for the following:

Table1 contains two relevant fields: home_state and job_state.  Both are 2 char state abbreviations.

Table2 also contains two relevant fields: state and region.  This table contains 50 rows, one for each US state.  Region is a one byte field containing 7 region codes 1..7.  These codes identify which US region the associated state is in.  The regions are essentially equivalent to northest, southeast, etc.

I want to build a report that shows, for each home_state region, the count of job_state regions. So the first row of the report would show, for all home_states in region 1, the number of job_states in regions 1..7,  one report column for each for the 7 job_state regions. The second row of the report would show for all home_states in region 2, the number of job_states in regions 1..7.  The last row of the report would show for all home_states in region 7, the number of job_states in regions 1..7.

I've tried a couple different joined tables with Group By region, but have had no success, and now I'm just confused.

Answer : SQL Question: Multiple tables and Group By

Hello Lenny,

I guess you will have to look for the problem elsewhere. My queries all work as posted. If needed, here is my test database: http://www.harfang.ch/expert/Q_21863083.zip

I'm guessing the problem has to do with the "SQL-enabled scripting language". As I don't know what it's capable of, I suggest you try to open the queries themselves from there or that you try variations of queries with named subqueries (instead of embedded subqueries).

Good luck!
(°v°)
Random Solutions  
 
programming4us programming4us