我在員工表中添加了一些數據,因爲我在下面的圖片中附加了這些數據,並且想要查詢它以查找每個年齡段的平均工資和員工百分比。我已經使用了下面的查詢,但我不知道如何包含avarage和百分比結果。請任何幫助。返回基於年齡範圍的數據的SQL查詢
SELECT emp.agerange as [age Range], count(emp.agerange) as [Number of employee on this age range]
FROM (
SELECT CASE
WHEN age >60 THEN '60 And Up'
WHEN age >=41 and age <=60 THEN '41-60'
WHEN age >=21 and age <=40 THEN '21-40'
WHEN age <=20 THEN '20 And Below' END as agerange
from kin.dbo.Employee) emp
group by emp.agerange
我只有一個表(employee),我可以得到的結果沒有使用左連接? –
@ Jhon.M是的,只要確保你在'emp'中包含任何你想要計算的字段。' –