attach]919232[/attach]过于复杂了,初次做SQL题,呵呵,
SELECT 部门,身份,部门评价,人数,IIF(身份="经理",IIF(部门评价="优秀",总数*0.5,IIF(部门评价="良好",总数*0.3,总数*0.2)),IIF(部门评价="优秀",总数*0.15,IIF(部门评价="良好",总数*0.55,总数*0.3))) AS 结果 FROM (SELECT A1.部门,A1.身份,A1.部门评价,A1.人数,A2.人数 AS 总数 FROM (SELECT 部门,身份,部门评价,SUM(人数) AS 人数 FROM (SELECT 部门,身份,部门评价,COUNT(姓名) AS 人数 FROM [评价明细$A3:D65535] WHERE 部门 IS NOT NULL GROUP BY 部门,身份,部门评价 UNION SELECT B1.部门,B2.身份,B3.部门评价,0 as 人数 FROM (select distinct 部门 FROM [评价明细$A3:D65535])B1,(select distinct 身份 FROM [评价明细$A3:D65535])B2,(select distinct 部门评价 FROM [评价明细$A3:D65535])B3) GROUP BY 部门,身份,部门评价)A1,(SELECT 部门,身份,SUM(人数) AS 人数 FROM (SELECT B1.部门 as 部门,B2.身份 AS 身份,B3.部门评价 AS 部门评价,0 as 人数 FROM (select distinct 部门 FROM [评价明细$A3:D65535])B1,(select distinct 身份 FROM [评价明细$A3:D65535])B2,(select distinct 部门评价 FROM [评价明细$A3:D65535])B3 union all (SELECT 部门,身份,部门评价,COUNT(姓名) AS 人数 FROM [评价明细$A3:D65535] WHERE 部门 IS NOT NULL GROUP BY 部门,身份,部门评价)) GROUP BY 部门,身份)A2 WHERE A1.部门&A1.身份=A2.部门&A2.身份)
[ 本帖最后由 chenhh803 于 2011-5-11 19:36 编辑 ] |