|
主题: 新做的几个SQL查询
|
蓝鲸
职务:版主
等级:5
金币:42.1
发贴:2614
|
#12005/4/1 0:10:09
刚做了个政绩考评系统,考证主要分两种,领导打分和工作人员互评,要求统计领导分和互评分,领导分占70%,互评30%。领导打分的考核内容与互评的考核内容是不一样的,领导分很细,而互评相对简单。 介绍一下统计所需要的表
表:Account_User(人员表) UserID UserName DepartmentID(部门ID) ...
表:Assess_GradeObject(领导发布考评项目) GradeObjectID(ID) CriterionTitleID(领导考核标准的ID,与考评标准表相关) Description(说明) PubDate(发布日期,作为月度标准时间) EndDate(考评项目时效日期) DepartmentID(部门ID)
表:Assess_Grade(领导评分表) GradeID(ID) UserID(被评人员) ObjectID(选用的考证项目ID) OperateUserName(评分人员姓名) TotalScore(总分) 注:本表为记录总分值,分项详细记录用Assess_GradeDetail记录详细打分情况
表:Assess_EachGrade(互评打分表) EachGradeID(ID) Description(考评详细记录) UserID(被评人员) ObjectID(选用的考证项目ID) OperateUserName(打分人员姓名) Point(总分)
编辑历史:[此帖最近一次被 蓝鲸 编辑过(编辑时间:2005-04-01 00:41:31)]
非常大鱼
|
蓝鲸
职务:版主
等级:5
金币:42.1
发贴:2614
|
#22005/4/1 0:27:34
如不觉累继续往下看,这些查询很累人,但实现的效果确实不错
每一种 实现按单位人员评比项目的具体情况,列表如下 姓名 互评(30%) 测评(70%) 综合得分 张一 26 65 91 李四 24 60 84
SELECT u.UserName, CAST(AVG(g.TotalScore)*0.7 AS INT) AS AvgGrade, CAST(AVG(e.Point)*0.3 AS INT) AS AvgEach, (CAST(AVG(g.TotalScore)*0.7 AS INT) + CAST(AVG(e.Point)*0.3 AS INT)) AS Total FROM Account_User u INNER JOIN Assess_Grade g ON u.UserID = g.UserID AND g.ObjectID = 5 INNER JOIN Assess_EachGrade e ON u.UserID = e.UserID AND e.ObjectID = 5 WHERE u.DepartmentID = 2 GROUP BY u.UserName -----------------------------------------------------------
非常大鱼
|
蓝鲸
职务:版主
等级:5
金币:42.1
发贴:2614
|
#32005/4/1 0:30:37
第二种 查询列表差不多,但第一列换成月份,查询某人从几月至几月的考评情况 本查询只查一个人的考证记录
SELECT DATEPART(month, o.PubDate) AS GradeMonth, CAST(AVG(g.TotalScore)*0.7 AS INT) AS AvgGrade, CAST(AVG(e.Point)*0.3 AS INT) AS AvgEach, (CAST(AVG(g.TotalScore)*0.7 AS INT) + CAST(AVG(e.Point)*0.3 AS INT)) AS Total FROM Assess_GradeObject o INNER JOIN Assess_Grade g ON g.ObjectID = o.GradeObjectID AND g.UserID = 8 INNER JOIN Assess_EachGrade e ON e.ObjectID = o.GradeObjectID AND e.UserID = 8 WHERE DATEPART(year, o.PubDate) = 2005 AND DATEPART(month, o.PubDate) >= 1 AND DATEPART(month, o.PubDate) <= 6 GROUP BY DATEPART(month, o.PubDate) -----------------------------------------------------------
本例查询UserID为8的,2005-1至6月的记录
非常大鱼
|
蓝鲸
职务:版主
等级:5
金币:42.1
发贴:2614
|
#42005/4/1 0:34:54
第三种 与第一种情况相似,但加上时间限制,查询从几月至几月,某部门,的考核情况
SELECT u.UserName, CAST(AVG(g.TotalScore)*0.7 AS INT) AS AvgGrade, CAST(AVG(e.Point)*0.3 AS INT) AS AvgEach, (CAST(AVG(g.TotalScore)*0.7 AS INT) + CAST(AVG(e.Point)*0.3 AS INT)) AS Total FROM Account_User u INNER JOIN Assess_Grade g ON u.UserID = g.UserID INNER JOIN Assess_EachGrade e ON u.UserID = e.UserID INNER JOIN Assess_GradeObject o ON g.ObjectID = o.GradeObjectID AND e.ObjectID = o.GradeObjectID WHERE u.DepartmentID = 2 AND DATEPART(year, o.PubDate) = 2005 AND DATEPART(month, o.PubDate) >= 1 AND DATEPART(month, o.PubDate) <= 6 GROUP BY u.UserName
也可写成 o.PubDate >= '2005-1-1' AND o.PubDate < '2005-7-1' 不过我喜欢前面的更清楚些
非常大鱼
|
holin
职务:普通成员
等级:1
金币:0.0
发贴:35
|
#52005/4/4 23:40:13
虽然不是很清楚,顶一个先
|