第一张表
name type 天数 日期
张三 1 2 2009-2-4
李四 3 1 2009-5-1
王五 2 3 2009-5-2
张三 2 1 2009-3-2
第二张表
typeid typename
1 事假
2 出差
3 病假
得到结果
姓名 事假 病假 出差
张三 2 1
谢谢
------解决方案--------------------------------------------------------
- SQL code
select name,sum(case typename when 事假 then 天数 end) 事假,sum(case typename when 病假 then 天数 end) 病假,sum(case typename when 出差 then 天数 end) 出差from table1 a,table2 bwhere a.type=b.type group by name;