从sqlserver 2008中的表中提取信息

时间:2014-06-26 11:37:30

标签: sql-server-2008

我在SQLServer 2008 R2中有以下结构

Emp_ID     Skill_ID     Skill_Name   _Skill_Level_ID   Skill_Level

 1           1           Carpenter       1              Beginner
 2           1           Mechanic        2              Advanced 
 3           2           Doctor          3              Moderate
 .           .
 .           .
 .           . 

我想要关注输出:

Skill_Name      Skill_Level   Count

Carpenter        Beginner     10
Carpenter        Moderate     12
Mechanic         Advanced     10
Mechanic         Moderate     10

我已经尝试了各种查询但没有工作。请指导我怎么做?

2 个答案:

答案 0 :(得分:1)

我认为这个简单的查询可以带来你的结果:

SELECT Skill_Name, Skill_Level,   Count(*) Counts
FROM YourTable
GROUP BY Skill_Name, Skill_Level
ORDER BY Skill_Name 

答案 1 :(得分:0)

试试这个

select COUNT(skill_id),skill_name,skill_level from skill group by skill_id,skill_name,skill_level