工资查询语句.sql 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. --34 [renyuan]
  3. select count(*) as cot from renyuan
  4. where name='KK' and dimission='在职'
  5. --name='KK' and dimission='在职';
  6. ------------------------------------------------------------------------------------------------------------
  7. --59 [dindanbukuanview]
  8. -- date属于收款日期;
  9. select count(*) as cot from dindanbukuanview
  10. where date>='2014-10-01' and date<='2014-10-31'
  11. --date>='2014-10-01' and date<='2014-10-31';
  12. ------------------------------------------------------------------------------------------------------------
  13. --60 [dindan]
  14. select count(*) as cot from dindan
  15. ------------------------------------------------------------------------------------------------------------
  16. --198 [singleincomemoneyview]
  17. -- date为补款时间;
  18. select count(*) as cot from singleincomemoneyview
  19. where date>='2014-10-01' and date<='2014-10-31' and renyuan3='KK'
  20. --date>='2014-10-01' and date<='2014-10-31' and renyuan3='KK';
  21. ------------------------------------------------------------------------------------------------------------
  22. --61 [dindan][dindanbukuan]
  23. --time2为拍照时间;
  24. select count(*) as cot from dindan
  25. where time2>='2014-10-01' and time2<='2014-10-31' and status='OK'
  26. -- date属于收款日期;
  27. select count(*) as cot from dindanbukuan
  28. where date<'2014-10-01'
  29. --time2>='2014-10-01' and time2<='2014-10-31' and status='OK'***date<'2014-10-01';
  30. ------------------------------------------------------------------------------------------------------------
  31. --142 [dindan][mywork] -datetime为工作安排时间,一般在计件式里用;
  32. select count(*) as cot from dindan
  33. select count(*) as cot from mywork
  34. where datetime>='2014-10-01' and datetime<='2014-10-31' and name='KK'
  35. --datetime>='2014-10-01' and datetime<='2014-10-31' and name='KK';
  36. ------------------------------------------------------------------------------------------------------------
  37. --192 [dindan][dindanjd] -date景点的拍照日期;
  38. select count(*) as cot from dindan
  39. select count(*) as cot from dindanjd
  40. where [date]>='2014-10-01' and [date]<='2014-10-31' and [status]='OK'
  41. and ([waiter1]='KK' or [waiter12]='KK' or [waiter2]='KK' or [waiter22]='KK')
  42. --[date]>='2014-10-01' and [date]<='2014-10-31' and [status]='OK' and ([waiter1]='KK' or [waiter12]='KK' or [waiter2]='KK' or [waiter22]='KK');
  43. ------------------------------------------------------------------------------------------------------------
  44. --193 [digitalview] -time8初修日期 -time9精修时间
  45. select count(*) as cot from digitalview
  46. where ([time8]>='2014-10-01' and [time8]<='2014-10-31' and [status4]='OK' and [waiter5]='KK')
  47. or ([time9]>='2014-10-01' and [time9]<='2014-10-31' and [status6]='OK' and [waiter7]='KK')
  48. or ([time10]>='2014-10-01' and [time10]<='2014-10-31' and [status5]='OK' and [waiter4]='KK')
  49. --([time8]>='2014-10-01' and [time8]<='2014-10-31' and [status4]='OK' and [waiter5]='KK') or ([time9]>='2014-10-01' and [time9]<='2014-10-31' and [status6]='OK' and [waiter7]='KK') or ([time10]>='2014-10-01' and [time10]<='2014-10-31' and [status5]='OK' and [waiter4]='KK') */ /************************************************************************/
  50. /*
  51. 程序编写: Jeff
  52. 版 本: V 1.0
  53. 建立日期: 2015-06-10
  54. 功能说明: 工资计算;
  55. 备 注:
  56. 修改日期:
  57. 修改说明:
  58. */
  59. /************************************************************************/
  60. use [db]
  61. declare @name nvarchar(36) --要计算工资的员工姓名;
  62. declare @btm nvarchar(24) --要计算工资的起始时间;
  63. declare @etm nvarchar(24) --要计算工资的结束时间;
  64. set @name = '覃琴'
  65. set @btm = '2015-06-01'
  66. set @etm = '2015-06-12'
  67. select * from renyuan where name = @name and dimission='在职'
  68. -- 工资有时计算不到,就是因为kind字段在客户端代码里只验证3和4;若用户自己添加的话,则是中一个数字;因此经常有收款数据没有计算到;
  69. select * from dindanbukuanview where date >= @btm and date <= @etm order by kind
  70. select * from singleincomemoneyview where date >= @btm and date <= @etm and renyuan3 = @name
  71. select * from dindan where time2 >= @btm and time2 <= @etm and status='OK'
  72. select * from dindanbukuan where date >= @btm and date <= @etm
  73. select * from mywork where datetime >= @btm and datetime <= @etm and name = @name
  74. select * from dindanjd where [date] >= @btm and [date] <= @btm and [status]='OK' and ([waiter1]=@name or [waiter12]=@name or [waiter2]=@name or [waiter22]=@name)
  75. select * from digitalview
  76. where ([time8] >= @btm and [time8] <= @btm and [status4]='OK' and [waiter5]=@name)
  77. or ([time9]>= @btm and [time9]<= @btm and [status6]='OK' and [waiter7]=@name)
  78. or ([time10]>= @btm and [time10]<= @btm and [status5]='OK' and [waiter4]=@name)
  79. GO
  80. ---------------------------------------------------------------------------------- /* 1.查询时间段 2.查询的员工 A.查询与该员工相关的所有订单号,与时间无关. select * from dindan where ([waiter1]='' or [waiter2]='' or [waiter3]='' or [waiter4]='' or [waiter5]='' or [waiter7]='' or [waiter8]='' or [waiter9]='' or [waiter12]='' or [waiter22]='') and ([status]='OK' or [status2]='OK' or [status4]='OK' or [status6]='OK' or [status5]='OK') --订单号+订单金额+订单时间+拍照OK时间+选片OK时间+初修OK时间+精修OK时间+设计OK时间+所有工作状态+所有流程人员 订单号+订单金额+订单时间+所有工作时间+所有工作状态+所有流程人员 B.查询该时间段内所有的收款记录,与时间有关. select * from dindanbukuan where date>='2014-10-01' and date<='2014-10-31' 订单号+收款金额+收款时间 C.查询B内出现的订单信息, select * from dindan where id in(select id from dindanbukuan where date>='2014-10-01' and date<='2014-10-31') 订单号+订单金额+订单时间+所有工作时间+所有工作状态+所有流程人员 D.查询A,B内出现的订单的收款记录,(或者只查A,B已查不需重复查) select * from dindanbukuan where id in(A) select * from dindanbukuan where id in(select id from dindan where ([waiter1]='刘璐璐' or [waiter2]='刘璐璐' or [waiter3]='刘璐璐' or [waiter4]='刘璐璐' or [waiter5]='刘璐璐' or [waiter7]='刘璐璐' or [waiter8]='刘璐璐' or [waiter9]='刘璐璐' or [waiter12]='刘璐璐' or [waiter22]='刘璐璐')) or (date>='2014-10-01' and date<='2014-10-31') E.查询其他二销singleincomemoneyview的收款记录 select * from singleincomemoneyview where date >='' and date <='' and renyuan3='' F.查询数码工作安排 select count(*) as cot from mywork
  81. where datetime>='2014-10-01' and datetime<='2014-10-31' and name='KK' H. */
  82. --------------------------------------------------------
  83. use [db]
  84. go
  85. declare @name nvarchar(50) --员工姓名;
  86. declare @btm nvarchar(24) --开始时间;
  87. declare @etm nvarchar(24) --结束时间;
  88. set @name = '覃琴'
  89. set @btm = '2015-06-01'
  90. set @etm = '2015-06-12'
  91. --1,首次过滤,查询该时间段内所有的收款记录,与时间有关(得到指定时间的收款订单号) --select * from dindanbukuan where date>=@btm and date<=@etm
  92. select * from dindanbukuanview where date>=@btm and date<=@etm order by id desc
  93. --2,再次过滤,查找出与员工有关的且出现在1中的订单(得到与指定员工有关的收款订单号)
  94. select * from dindan where ([waiter1]=@name --摄影 or [waiter2]=@name --化妆 or [waiter3]=@name --选片 or [waiter4]=@name --设计 or [waiter5]=@name --初修 or [waiter5]=@name --接单 or [waiter7]=@name --精修 or [waiter8]=@name --看样 or [waiter9]=@name --???? or [waiter12]=@name --摄影助理 or [waiter22]=@name) --化妆助理 and id in (select id from dindanbukuanview where date>=@btm and date<=@etm) order by id desc
  95. --2,再次过滤,查找出与员工有关的且出现在1中的订单(得到与指定员工有关的收款订单号)
  96. select id, status, status2, status3, status4, status5, status6, status7,status8,
  97. money1, money2, money3, taoxijiage, time1,time2,time3, time4, time5, time6, time7, time8, time9, time10, ren, discount, payed1, payed2, payed3, payed4, payed5,
  98. waiter1, waiter12, waiter13, waiter14, waiter2, waiter22, waiter23, waiter24, waiter3, waiter4, waiter5, waiter6, waiter7, waiter8, waiter9 from dindan where
  99. ([waiter1]=@name --摄影
  100. or [waiter2]=@name --化妆
  101. or [waiter3]=@name --选片
  102. or [waiter4]=@name --设计
  103. or [waiter5]=@name --初修
  104. or [waiter5]=@name --接单
  105. or [waiter7]=@name --精修
  106. or [waiter8]=@name --看样
  107. or [waiter9]=@name --????
  108. or [waiter12]=@name --摄影助理
  109. or [waiter22]=@name) --化妆助理
  110. and id in (select id from dindanbukuanview where date>=@btm and date<=@etm) order by id desc --3,再次过滤,得到与指定员工有关的指定时间的收款订单号; select * from dindanbukuanview where id in (select id from dindan where ([waiter1]=@name --摄影 or [waiter2]=@name --化妆 or [waiter3]=@name --选片 or [waiter4]=@name --设计 or [waiter5]=@name --初修 or [waiter5]=@name --接单 or [waiter7]=@name --精修 or [waiter8]=@name --看样 or [waiter9]=@name --???? or [waiter12]=@name --摄影助理 or [waiter22]=@name) --化妆助理 and id in (select id from dindanbukuanview where date>=@btm and date<=@etm)) and date>=@btm and date<=@etm order by id desc --4,获取其他收入; select * from singleincomemoneyview where date >= @btm and date <= @etm and renyuan3 = @name --5,数码师工作; select * from mywork where datetime >= @btm and datetime <= @etm and name = @name
  111. create view [dbo].[Payroll] as select
  112. dbo.dindan.name1,
  113. dbo.dindan.name2,
  114. dbo.dindan.txtype,
  115. dbo.dindan.taoxiname,
  116. dbo.dindanbukuan.money,
  117. (case when dbo.dindan.time2 > dbo.dindanbukuan.date then dbo.dindan.time2 else dbo.dindanbukuan.date end) as Paydate,
  118. dbo.dindanbukuan.kind,
  119. dbo.dindanbukuan.ren,
  120. dbo.dindanbukuan.bz,
  121. dbo.dindanbukuan.id,
  122. dbo.dindanbukuan.paytype from dbo.dindan
  123. inner JOIN dbo.dindanbukuan ON dbo.dindan.id = dbo.dindanbukuan.id
  124. and dbo.dindan.status = 'OK'
  125. GO
  126. */
  127. /*
  128. select * from (
  129. select
  130. dbo.dindan.status,
  131. dbo.dindan.name1,
  132. dbo.dindan.name2,
  133. dbo.dindan.txtype,
  134. dbo.dindan.taoxiname,
  135. dbo.dindan.time2,
  136. dbo.dindanbukuan.money,
  137. dbo.dindanbukuan.date,
  138. (case when dbo.dindan.time2 > dbo.dindanbukuan.date then dbo.dindan.time2 else dbo.dindanbukuan.date end) as Paydate,
  139. dbo.dindanbukuan.kind,
  140. dbo.dindanbukuan.ren,
  141. dbo.dindanbukuan.bz,
  142. dbo.dindanbukuan.id,
  143. dbo.dindanbukuan.paytype from dbo.dindan
  144. INNER JOIN dbo.dindanbukuan ON dbo.dindan.id = dbo.dindanbukuan.id
  145. ) t where status = 'OK' and time2 > date
  146. */
  147. -- 查询出订单拍照OK的所有订单(不是取件OK的);
  148. --select * from [dbo].[dindan] where [dbo].[dindan].[status] = 'OK' and [dbo].[dindan].[time2] > [dbo].[dindanbukuan].[date]
  149. --select * from
  150. --(select * from [dbo].[dindan] INNER JOIN dbo.dindanbukuan ON dbo.dindan.id = dbo.dindanbukuan.id ) where [dbo].[dindan].[status] = 'OK' and [dbo].[dindan].[time2] > [dbo].[dindanbukuan].[date]
  151. select
  152. dbo.dindan.name1,
  153. dbo.dindan.name2,
  154. dbo.dindan.txtype,
  155. dbo.dindan.taoxiname,
  156. dbo.dindanbukuan.money,
  157. (case when dbo.dindan.time2 > dbo.dindanbukuan.date then dbo.dindan.time2 else dbo.dindanbukuan.date end) as Paydate,
  158. dbo.dindanbukuan.kind,
  159. dbo.dindanbukuan.ren,
  160. dbo.dindanbukuan.bz,
  161. dbo.dindanbukuan.id,
  162. dbo.dindanbukuan.paytype from dbo.dindan
  163. left JOIN dbo.dindanbukuan ON dbo.dindan.id = dbo.dindanbukuan.id
  164. where dbo.dindan.status = 'OK'
  165. select count(*) from dindan
  166. select count(*) from dindanbukuan
  167. select
  168. dbo.dindan.name1,
  169. dbo.dindan.name2,
  170. dbo.dindan.txtype,
  171. dbo.dindan.taoxiname,
  172. dbo.dindanbukuan.money,
  173. (case when dbo.dindan.time2 > dbo.dindanbukuan.date then dbo.dindan.time2 else dbo.dindanbukuan.date end) as Paydate,
  174. (case when dbo.dindan.time2 > dbo.dindanbukuan.date then 0 else 1 end) as Pay,
  175. dbo.dindanbukuan.kind,
  176. dbo.dindanbukuan.ren,
  177. dbo.dindanbukuan.bz,
  178. dbo.dindanbukuan.id,
  179. dbo.dindanbukuan.paytype from dbo.dindan
  180. inner JOIN dbo.dindanbukuan ON dbo.dindan.id = dbo.dindanbukuan.id
  181. where dbo.dindan.status = 'OK'-- and dbo.dindan.time2 > dbo.dindanbukuan.date
  182. ---------------------------------------------------------------------------------------------------------------------------------