Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据年龄段创建分析数据的Sql查询_Sql_Oracle - Fatal编程技术网

根据年龄段创建分析数据的Sql查询

根据年龄段创建分析数据的Sql查询,sql,oracle,Sql,Oracle,重新思考我的问题- 问题#1 上面的查询提供了以下格式的数据- person_number taxable_earn Basic_Life_EE Tax_Units Basic_Spouse depent_dob age_EE 10 78.9 10.5

重新思考我的问题-

问题#1

上面的查询提供了以下格式的数据-

person_number        taxable_earn       Basic_Life_EE            Tax_Units      Basic_Spouse     depent_dob   age_EE
   10                 78.9                                          10.5                                        39
   20                 76.7                  10.2                                12.3                32          21
   30                  2.3                  10.3                    8.9         19.0                34          25
   40                                       14.3                    8.9         19.0                52          67
   50                                       3.2                                                                 20
   60                                       5.2                                                                 42
   70                                       7.2                                                                 49
   80                                       6.2                                                                 55      
现在我想创建一个查询,根据元素Basic_Life_EE的年龄段来分隔数据-

Age_Bracket        Count         SUM OF  Basic_Life_EE                   
    <=25            3                   23.7                                    
    26-29           
    30-34                                                                          
    35-39                                                               
    40-44           1                   5.2 
    45-49           1                   7.2        
    50-54          
    55-59           1                   6.2
    60-64
    65-69           1                   14.3                
    70+
Age\u括号计数基本寿命之和

如果可以硬编码年龄段,则可以这样做


选择sum(basic_life_ee),count(1),“您想如何创建年龄段,还是它已经存储在任何列中?这就是问题所在。”。。它不是存储在任何地方,而是固定的,因此可以硬编码…如果您看到上面给出的表,它包含所有列的年龄数据-应纳税收入、纳税单位。上面的查询正在计算除基本生活元素之外的其他元素的“计数”…而不仅仅是包含基本生活元素的员工的年龄抱歉,我无法理解您的观点。如果查询结果不正确,请举例说明。
Age_Bracket        Count         SUM OF  Basic_Life_EE                   
    <=25            3                   23.7                                    
    26-29           
    30-34                                                                          
    35-39                                                               
    40-44           1                   5.2 
    45-49           1                   7.2        
    50-54          
    55-59           1                   6.2
    60-64
    65-69           1                   14.3                
    70+
    select sum(basic_life_ee), count(1), '<=25' as age_bracket from Age_bracket_test where age_ee <=25
union
select sum(basic_life_ee), count(1), '26-29' as age_bracket from Age_bracket_test where age_ee between 26 and 29;
with age_temp(min_age, max_age, age_bracket) as 
(select 0, 25, '<=25' age_bracket from Age_bracket_test
union
select 26, 29, '26-29' age_bracket from Age_bracket_test
union
select 30, 34,  '30-34' age_bracket from Age_bracket_test
union
select 35, 39, '35-39' age_bracket from Age_bracket_test
union
select 40, 44, '40-44' age_bracket from Age_bracket_test
union
select 45, 49, '45-49' age_bracket from Age_bracket_test
union
select 50, 54, '50-54' age_bracket from Age_bracket_test
union
select 55, 59, '55-59' age_bracket from Age_bracket_test
union
select 60, 64, '60-64' age_bracket from Age_bracket_test
union
select 65, 69, '65-69' age_bracket from Age_bracket_test
union
select 70, null, '70+' age_bracket from Age_bracket_test)
select sum(basic_life_ee), count(1),  age_bracket from Age_bracket_test, age_temp where age_bracket in ('<=25', '26-29', '40-44', '30-34', '35-40', '46-49', '50-54', '55-59', '60-64', '65-79', '70+') and age_ee between min_age and max_age group by age_bracket