所以我对 SQL 很陌生,到目前为止几乎完全是自学的。我目前正在尝试对员工的等级进行一些分析,我正在尝试将大约 15 个以上的等级“重新分类”为 4 个等级类别。然后我想按这些类别进行分组,但遇到了一些麻烦(SQL for Dummies 似乎已经失去动力,或者我找不到答案......)。
无论如何,我目前的查询如下。这给出了 group by 必须包含一个不是外部引用的列的错误,我理解,但不知道如何解决。
编辑:我的目标是得到一个结果,它给了我以下信息:
RANK Hours etc
Equity Partner 12
Fixed Share Partner 20
Associate 50
Trainee 25
Other 15
任何帮助将不胜感激马特
declare @startperiod as integer
declare @endperiod as integer
declare @offc as integer
declare @dept as varchar(3)
select @startperiod = '201101'
select @endperiod = '201112'
select @offc = '55'
select
case k.rank_code
when '10' then 'Equity Partner'
when '110' then 'Fixed Share Partner'
when '130' then 'Associate'
when '131' then 'Associate'
When '132' then 'Associate'
when '133' then 'Associate'
when '134' then 'Associate'
when '135' then 'Associate'
when '136' then 'Associate'
when '137' then 'Associate'
when '141' then 'Associate'
when '142' then 'Associate'
when '341' then 'Trainee'
when '342' then 'Trainee'
else 'Other'
end as 'Rank Desc',
sum(b.base_hrs) as 'Base Hrs',sum(b.tobill_hrs) as 'ToBill Hrs',sum(b.billed_hrs) as 'Billed Hrs',
sum(b.base_amt) as 'Base Amt',sum(b.tobill_amt) as 'ToBill Amt',sum(b.billed_amt) as 'Billed Amt'
from blh_billed_fees b, tbl_rank k, tbm_persnl p
where b.tk_empl_uno = p.empl_uno
and p.rank_code = k.rank_code
group by 'Rank Desc'