Manipulate results to display rows as columns

前端 未结 3 826
终归单人心
终归单人心 2020-12-19 18:07

I have two tables. Table A contains a list of departments, there are 20 in total.

See image

\"enter

3条回答
  •  攒了一身酷
    2020-12-19 19:08

    Try this:

    select A.DEPTNAME, 
           sum(case when B.EMPLOYEE_CLASS='Full time' then B.STAFF_NO else 0) as FullTimeNo,
           sum(case when B.EMPLOYEE_CLASS='Part time' then B.STAFF_NO else 0) as PartTimeNo,
    from TabA A
    join TabB B on A.DEPTNAME=B.DEPTNAME
    group by A.DEPTNAME
    

提交回复
热议问题