USE [Employee]
GO
/****** Object: Table [dbo].[Commission] Script Date: 2019/11/17 14:10:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Commission](
[ComID] [int] IDENTITY(1,1) NOT NULL,
[ComRatio] [float] NULL,
[ComStartNum] [int] NULL,
[ComEndNum] [int] NULL,
PRIMARY KEY CLUSTERED
(
[ComID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO
/****** Object: Table [dbo].[Department] Script Date: 2019/11/17 14:10:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Department](
[DepID] [int] IDENTITY(1,1) NOT NULL,
[DepName] [varchar](50) NULL,
[DepAddress] [varchar](50) NULL,
[DepJobContent] [varchar](200) NULL,
PRIMARY KEY CLUSTERED
(
[DepID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Employees] Script Date: 2019/11/17 14:10:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Employees](
[EmpID] [int] IDENTITY(1,1) NOT NULL,
[DepID] [int] NULL,
[EmpName] [varchar](50) NULL,
[EmpSex] [int] NULL,
[EmpTel] [varchar](13) NULL,
PRIMARY KEY CLUSTERED
(
[EmpID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Performance] Script Date: 2019/11/17 14:10:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Performance](
[PerID] [int] IDENTITY(1,1) NOT NULL,
[EmpID] [int] NULL,
[PerCount] [int] NULL,
[PerContent] [varchar](200) NULL,
[IsCommission] [int] NULL,
PRIMARY KEY CLUSTERED
(
[PerID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Commission] ON GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (1, 0.05, 0, 2000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (2, 0.1, 2001, 8000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (3, 0.15, 8001, 20000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (4, 0.2, 20001, 40000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (5, 0.25, 40001, 80000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (6, 0.3, 80001, 120000)
GO
INSERT [dbo].[Commission] ([ComID], [ComRatio], [ComStartNum], [ComEndNum]) VALUES (7, 0.35, 120000, 2000000)
GO
SET IDENTITY_INSERT [dbo].[Commission] OFF
GO
SET IDENTITY_INSERT [dbo].[Department] ON GO
INSERT [dbo].[Department] ([DepID], [DepName], [DepAddress], [DepJobContent]) VALUES (1, N'财务部', N'1701室', N'负责公司整体财务进出账管理')
GO
INSERT [dbo].[Department] ([DepID], [DepName], [DepAddress], [DepJobContent]) VALUES (2, N'技术部', N'1702-1706室', N'负责公司技术方案指定.开发.实施')
GO
INSERT [dbo].[Department] ([DepID], [DepName], [DepAddress], [DepJobContent]) VALUES (3, N'人事部', N'1707室', N'负责公司员工招聘,福利待遇')
GO
INSERT [dbo].[Department] ([DepID], [DepName], [DepAddress], [DepJobContent]) VALUES (4, N'行政部', N'1708室', N'负责公司办公设备采购,登记')
GO
INSERT [dbo].[Department] ([DepID], [DepName], [DepAddress], [DepJobContent]) VALUES (5, N'业务部', N'1709-1719室', N'负责公司产品的销售和客户的拓展,维护')
GO
SET IDENTITY_INSERT [dbo].[Department] OFF
GO
SET IDENTITY_INSERT [dbo].[Employees] ON GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (1, 1, N'刘忠田', 1, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (2, 2, N'吕泽强', 1, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (3, 3, N'丁伟亮', 1, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (4, 4, N'马建', 0, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (5, 5, N'孙晓红', 0, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (6, 1, N'李玲', 0, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (7, 2, N'李子明', 0, N'')
GO
INSERT [dbo].[Employees] ([EmpID], [DepID], [EmpName], [EmpSex], [EmpTel]) VALUES (8, 3, N'马欢', 0, N'')
GO
SET IDENTITY_INSERT [dbo].[Employees] OFF
GO
SET IDENTITY_INSERT [dbo].[Performance] ON GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (1, 5, 3000, N'某产品10公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (2, 6, 7000, N'某产品50公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (3, 7, 9000, N'某产品150公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (4, 8, 10000, N'某产品250公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (5, 8, 13000, N'某产品250公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (6, 8, 150000, N'某产品250公斤', 1)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (7, 2, 2000, N'公司产品管理系统开发奖金', 0)
GO
INSERT [dbo].[Performance] ([PerID], [EmpID], [PerCount], [PerContent], [IsCommission]) VALUES (8, 3, 2000, N'某产品公司产品管理系统开发奖金公斤', 0)
GO
SET IDENTITY_INSERT [dbo].[Performance] OFF
GO
ALTER TABLE [dbo].[Employees] WITH CHECK ADD FOREIGN KEY([DepID])
REFERENCES [dbo].[Department] ([DepID])
GO
ALTER TABLE [dbo].[Performance] WITH CHECK ADD FOREIGN KEY([EmpID])
REFERENCES [dbo].[Employees] ([EmpID])
GO SELECT b.EmpName AS 员工姓名, b.PerCount AS 业绩,b.ComRatio AS 提成比例,b.PerCount * b.ComRatio AS 提成金额
FROM (
SELECT a.EmpName,a.PerCount
,(SELECT ComRatio FROM dbo.Commission WHERE a.perCount BETWEEN ComStartNum AND ComEndNum) AS ComRatio
FROM(
SELECT b.EmpName,SUM(a.PerCount) AS PerCount
FROM dbo.Performance a INNER JOIN dbo.Employees b
ON a.EmpID = b.EmpID
GROUP BY b.EmpName
) a
) b
ORDER BY b.ComRatio

SQLSERVER根据提成比率区间计算业绩提成的更多相关文章

  1. sqlserver varchar转datate 加计算

    SELECT * from mconsumeinfo mo where CONVERT(Datetime, mo.financedate, 120)> dateadd(day,-180,getd ...

  2. excel VLOOKUP函数的使用方法 .

    VLOOKUP函数是Excel中几个最重函数之一,为了方便大家学习,兰色幻想特针对VLOOKUP函数的使用和扩展应用,进行一次全面综合的说明.本文为入门部分 一.入门级 VLOOKUP是一个查找函数, ...

  3. excel VLOOKUP函数的用法

    VLOOKUP函数是Excel中几个最重函数之中的一个,为了方便大家学习,兰色幻想特针对VLOOKUP函数的使用和扩展应用,进行一次全面综合的说明.本文为入门部分 一.入门级 VLOOKUP是一个查找 ...

  4. Python_每日习题_0002_个税计算

    # 题目 企业发放的奖金根据利润提成.利润(I)低于或等于10万元时, # 奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成, # 高于10万元的部分,可提成7.%:2 ...

  5. mssql sqlserver 索引专题

    摘要: 下文将详细讲述sql server 索引的相关知识,如下所示: 实验环境: sql server 2008 R2 sqlserver索引简介: mssql sqlsever 索引分类简介 ms ...

  6. vijos 1439 区间

    区间 背景 描述 给定n个闭区间 [ai,bi], i=1,2,...,n. 这些区间的和可以用两两不相交的闭区间的和来表示.你的任务是找到这样的区间数目最少的表示,且把它们按升序的方式写到输出文件中 ...

  7. 「BZOJ 4565」「HAOI 2016」字符合并「区间状压DP」

    题意 给一个长度为\(n(\leq 300)\)的\(01\)串,每次可以把\(k(\leq 8)\)个相邻字符合并,得到新字符和一定分数,最大化最后的得分 题解 考虑设计dp:\(dp[S][i][ ...

  8. ST表 求 RMQ(区间最值)

    RMQ即Range Minimum/Maximun Query,中文意思:查询一个区间的最小值/最大值 比如有这样一个数组:A{3 2 4 5 6 8 1 2 9 7},然后问你若干问题: 数组A下标 ...

  9. Odoo:全球第一免费开源ERP 人力资源模块操作指南(完美珍藏版)

    概述 人力资源管理概述 一般企业里,和人力资源相关的工作有:1)员工合同管理,即员工基本档案管理:2)招聘管理,即岗位及岗位人员补充管理:3)员工薪资计算: 4)员工考勤:5)员工休假管理:6)员工绩 ...

随机推荐

  1. ABAP-表修改日志存储

    1.设置了变更文档的,可以通过查看标准表CDHDR,CDPOS SE38   --  RSUSR200   ST03N -- 专家模式 2.SE16N维护的数据,可以查看表SE16N_CD_KEY,S ...

  2. Mybatis 中的转义字符及常用查询

    转译符 1.特殊字符转译 < < 小于 > > 大于 & & 与 ' ’ 单引号 " " 双引号 需要注意的是分号是必不可少的. 比如 a ...

  3. vsftp 常见配置测试与故障排除

    匿名用户 /var/ftp        本地用户 /home/username配置vsftpd时,强烈建议·# cp /etc/vsftpd.conf /etc/vsftpd.conf1       ...

  4. wokerman随笔

    linux环境检查是否满足workerman要求: curl -Ss http://www.workerman.net/check.php | php workerman依赖扩展:pcntl扩展.po ...

  5. scrapy随机切换user-agent

    使用github的 scrapy-fake-useragent 不用自己改源码继承自带的userAgent中间件  只需要安装后增加配置即可 https://github.com/alecxe/scr ...

  6. HTMLTestRunner 用PyCharm执行测试成功但无法生成报告问题

    在pythoncharm中运行时,运行成功,但是没有生成测试报告这个问题 代码: if __name__ == '__main__': # 创建测试套件suite suite = unittest.T ...

  7. H3C WLAN相关组织和标准

  8. http,socket,进程通信,网络通信(1)

    众所周知,网络通信本质上就是进程间通信,进程间通信有以下常见的通信方式: 1,管道pipe:管道是一种半双工的通信方式,数据只能单向流动,而且只能在具有亲缘关系的进程间使用,进程的亲缘关系通常指父子进 ...

  9. jquery 内容筛选选择器

    基本筛选选择器针对的都是元素DOM节点,如果我们要通过内容来过滤,jQuery也提供了一组内容筛选选择器,当然其规则也会体现在它所包含的子元素或者文本内容上 注意事项: :contains与:has都 ...

  10. MERGE引擎 分表后 快速查询所有数据

    MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询.构成一个MERGE数据表结构的各成员MyISAM数据表必须具有完全一样的结构.每一个成员数据表的数据列必 ...