脑袋有点大,先谢谢各位高手了--单位基本信息表
CREATE TABLE [dbo].[Branch](
[ID] [uniqueidentifier] NULL,
[BranchName] [varchar](100) NOT NULL,
[IsUse] [char](1) NULL
) ON [PRIMARY]
insert into Branch select '095a9817-98e3-4c67-8c0f-c60cd48afb9b','一分厂','1'
insert into Branch select 'b59f8f76-3410-4887-898d-9803c8278170','二分厂','1'
insert into Branch select '370e564f-bd23-4b78-a76a-7c4e138c15fd','三分厂','1'
insert into Branch select '664fc11a-3340-4a3d-b610-95d48fd22c29','四分厂','1'
----单位打分表
CREATE TABLE [dbo].[Ratingtable](
[ratingtableid] [uniqueidentifier] NOT NULL,
[Plusdepartforid] [uniqueidentifier] NOT NULL,
[Plusdepartfromid] [uniqueidentifier] NOT NULL,
[Average] [decimal](18, 2) NULL,
[Ratingmonth] [smalldatetime] NULL
)
insert into Ratingtable select '7a597209-8e03-4b69-9bc4-b255b9cf5fc6','095a9817-98e3-4c67-8c0f-c60cd48afb9b','370e564f-bd23-4b78-a76a-7c4e138c15fd','98','2011-03-22'
----单位评分类别表
CREATE TABLE [dbo].[RatingTemplate](
[ratingtemplateid] [uniqueidentifier] NOT NULL,
[templatedate] [smalldatetime] NULL,
[ratingdepartid] [uniqueidentifier] NULL,
[ratingBclass] [varchar](100) NULL,
[ratingclass] [varchar](100) NULL,
[ratingpercentage] [numeric](10, 2) NULL,
)
insert into RatingTemplate select '2d397209-8e03-4b69-9bc4-b255b9cf5fc6','2011-03-23','095a9817-98e3-4c67-8c0f-c60cd48afb9b','a','0','0.2'
----里面的几个字段的关系是
--Branch.ID
--Ratingtable.Plusdepartforid
--Ratingtable.Plusdepartfromid
--RatingTemplate.ratingdepartid
--这几个字段都可以对应同一单位
---依据上面的3张表,要得到如下类似的结果:
--得分单位 一分厂 二分厂 三分厂 四分厂 考评分
--一分厂 90 93 94 88 89
--二分厂 93 94 94 99
--三分厂 94 93 88 90
--四分厂 91 92 94 88 89------可能打分不完全:有的单位没有给其他单位打分 则留空格 考评分为RatingTemplate中的ratingpercentage与Ratingtable
--表中对应的单位(RatingTemplate.ratingdepartid与Ratingtable.Plusdepartfromid对应)打分Average相乘后之和(如一分厂*0.5+二分厂 *0.9)得出
CREATE TABLE [dbo].[Branch](
[ID] [uniqueidentifier] NULL,
[BranchName] [varchar](100) NOT NULL,
[IsUse] [char](1) NULL
) ON [PRIMARY]
insert into Branch select '095a9817-98e3-4c67-8c0f-c60cd48afb9b','一分厂','1'
insert into Branch select 'b59f8f76-3410-4887-898d-9803c8278170','二分厂','1'
insert into Branch select '370e564f-bd23-4b78-a76a-7c4e138c15fd','三分厂','1'
insert into Branch select '664fc11a-3340-4a3d-b610-95d48fd22c29','四分厂','1'
----单位打分表
CREATE TABLE [dbo].[Ratingtable](
[ratingtableid] [uniqueidentifier] NOT NULL,
[Plusdepartforid] [uniqueidentifier] NOT NULL,
[Plusdepartfromid] [uniqueidentifier] NOT NULL,
[Average] [decimal](18, 2) NULL,
[Ratingmonth] [smalldatetime] NULL
)
insert into Ratingtable select '7a597209-8e03-4b69-9bc4-b255b9cf5fc6','095a9817-98e3-4c67-8c0f-c60cd48afb9b','370e564f-bd23-4b78-a76a-7c4e138c15fd','98','2011-03-22'
----单位评分类别表
CREATE TABLE [dbo].[RatingTemplate](
[ratingtemplateid] [uniqueidentifier] NOT NULL,
[templatedate] [smalldatetime] NULL,
[ratingdepartid] [uniqueidentifier] NULL,
[ratingBclass] [varchar](100) NULL,
[ratingclass] [varchar](100) NULL,
[ratingpercentage] [numeric](10, 2) NULL,
)
insert into RatingTemplate select '2d397209-8e03-4b69-9bc4-b255b9cf5fc6','2011-03-23','095a9817-98e3-4c67-8c0f-c60cd48afb9b','a','0','0.2'
----里面的几个字段的关系是
--Branch.ID
--Ratingtable.Plusdepartforid
--Ratingtable.Plusdepartfromid
--RatingTemplate.ratingdepartid
--这几个字段都可以对应同一单位
---依据上面的3张表,要得到如下类似的结果:
--得分单位 一分厂 二分厂 三分厂 四分厂 考评分
--一分厂 90 93 94 88 89
--二分厂 93 94 94 99
--三分厂 94 93 88 90
--四分厂 91 92 94 88 89------可能打分不完全:有的单位没有给其他单位打分 则留空格 考评分为RatingTemplate中的ratingpercentage与Ratingtable
--表中对应的单位(RatingTemplate.ratingdepartid与Ratingtable.Plusdepartfromid对应)打分Average相乘后之和(如一分厂*0.5+二分厂 *0.9)得出
考评分是单位打分表Ratingtable里的Average与对应的单位评分类别表RatingTemplate里的ratingpercentage相乘后的之和,比如说1分厂的分数*ratingpercentage再加上2分厂的分数*ratingpercentage.........
单位打分表Ratingtable与单位评分类别表RatingTemplate是按--Ratingtable.Plusdepartfromid
--RatingTemplate.ratingdepartid对应的。