工资管理统计.sql 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. --update tb_ErpPayment set Pay_ViceNumber = (select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number = Pay_OrdNumber And Ordpg_Sights = Pay_ShootingName) where Pay_ViceNumber is null
  2. --GO
  3. --update tb_ErpPayment set Pay_ViceNumber = '' where Pay_ViceNumber is null
  4. --订单前期提成 应收、实收、全款
  5. select Pay_OrdNumber,
  6. Pay_ViceNumber,
  7. Pay_ShootingName,
  8. Pay_Category,
  9. Pay_TwoPinsCategory,
  10. (Pay_AmountOf - Pay_DiscountAmount) as PaidAmount,
  11. Pay_AmountOf,
  12. Pay_PaymentDiscount,
  13. Pay_DiscountAmount,
  14. Pay_OpenSingle,
  15. Pay_CreateName,
  16. Pay_Type,
  17. Pay_DividedShop,
  18. Pay_PaymentMethod,
  19. Pay_ReceivableProject,
  20. Pay_CreateDatetime from [dbo].[tb_ErpPayment] where Pay_Type =0
  21. --实收 前期的 全款、预约收款、补款
  22. select * from [dbo].[tb_ErpPayment] where Pay_Type =0 and Pay_Category in('预约收款','预约补款','全款') and Pay_OpenSingle like '%20150507102012365%'
  23. --实收 后期收款
  24. select * from [dbo].[tb_ErpPayment] where Pay_Type =0 and Pay_Category ='后期收款' and Pay_OpenSingle like '%20150507102012365%'
  25. --其他消费收款
  26. select * from [dbo].[tb_ErpPayment] where Pay_Type =1
  27. --礼服租售收款
  28. select * from [dbo].[tb_ErpPayment] where Pay_Type =2
  29. --订单前期 应收
  30. with t as
  31. (
  32. select OrdPe_OrderNumber, dbo.AggregateString([OrdPe_OrdersPerson]+'{$$},{$$}s') as OrdPe_OrdersPerson from dbo.tb_ErpOrdersPerson
  33. group by OrdPe_OrderNumber
  34. )
  35. select Ord_DividedShop,Ord_Number,Ord_SinceOrderNumber,Ord_Mc_Number,Ord_Type,Ord_Class,Ord_OrderClass,Ord_PhotographyCategory,Ord_SeriesName,Ord_SeriesPrice,Ord_PackageName,Ord_PackagePrice,Ord_CreateDateTime
  36. ,OrdPe_OrdersPerson from dbo.tb_ErpOrder
  37. left join t on Ord_Number= OrdPe_OrderNumber
  38. where Ord_Class=1
  39. --会员充值记录表
  40. select Mcrr_Number,Mcrr_RechargeNumber,Mcrr_RechargeName,Mcrr_RechargeAmount,Mcrr_DonateAmount,Mcrr_DonateDiscount,Mcrr_PaymentMethod,Mcrr_OrderPerson
  41. ,Mcrr_CreateDatetime,Mcrr_CreateName,Mcrr_DividedShop
  42. from tb_ErpMemberCardRechargeRecord
  43. --会员服务收款表
  44. select Mcpt_PaymentNumber,
  45. Mcpt_Number,
  46. Mcpt_PaymentType ,
  47. Mcpt_PaymentAmount,
  48. Mcpt_PaymentMethod,Mcpt_PackageClass ,Mcpt_PackagePrice ,
  49. Mcpt_Discount,
  50. Mcpt_DiscountAmount ,
  51. Mcpt_OrderPerson ,
  52. Mcpt_CreateDatetime ,
  53. Mcpt_CreateName ,
  54. Mcpt_DividedShop
  55. from tb_ErpMemberCardPayment
  56. --计件提成表
  57. select Pcr_OrderNumber,
  58. Pcr_DigitalDivision ,
  59. Pcr_Date ,
  60. Pcr_CompletionContents ,
  61. Pcr_Quantity ,
  62. Pcr_Type ,
  63. Pcr_MarkKey ,
  64. Pcr_CreateTime,
  65. Pcr_EntryPeople ,
  66. Pcr_DividedShop
  67. from tb_ErpPieceCommissionRecords
  68. --奖罚记录表
  69. select Rp_Type,
  70. Rp_RelevantPeople,
  71. Rp_Money,
  72. Rp_Status ,
  73. Rp_RPDatetime ,
  74. Rp_Reason ,
  75. Rp_Remark ,
  76. Rp_CreateDatetime,
  77. Rp_CreateName,
  78. Rp_DividedShop
  79. from tb_ErpRewardPunishment
  80. select * from tb_ErpSatisfactionSurveySet order by sfss_type
  81. --满意度调查表
  82. select Sfs_OrderNumber,
  83. Sfs_OrderNumberDeputy,
  84. Sfs_EmployeeID,
  85. Sfs_Type,
  86. Sfs_SurveySetID,
  87. Sfs_ReturningMattersSetID,
  88. Sfs_RatingSetID,
  89. Sfs_OtherID,
  90. Sfs_Remark,
  91. Sfs_CreateName,
  92. Sfs_CreateTime
  93. ,Sfss_Name
  94. ,Sfrms_Contents
  95. ,Sfrs_Name,Sfrs_Scores
  96. from tb_ErpSatisfactionSurvey
  97. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  98. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  99. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  100. where Sfs_SurveySetID=1
  101. --统计门市总分值
  102. select Sfs_OrderNumber,
  103. (sum(Sfrs_Scores)/count(1)) as sumScores
  104. from tb_ErpSatisfactionSurvey
  105. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  106. where Sfs_SurveySetID=1
  107. group by Sfs_OrderNumber
  108. select * from tb_ErpSatisfactionSurvey
  109. select * from tb_ErpSatisfactionSurveySet --满意度调查对象设置表
  110. select * from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=1 --满意度调查回访事项设置表
  111. select * from tb_ErpSatisfactionRatingSet
  112. select Sfss_Name,Sfss_MarkID from tb_ErpSatisfactionSurveySet
  113. select * from Vw_ErpSatisfactionSurvey
  114. select * from [dbo].[vw_Select_OrdersPersonList]
  115. select * from dbo.tb_ErpOrdersPhotography where id=1519
  116. select * from dbo.tb_ErpOrderDigital
  117. --组合订单信息
  118. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_Select_OrdersPersonList]'))
  119. DROP VIEW [dbo].[vw_Select_OrdersPersonList]
  120. GO
  121. CREATE VIEW dbo.vw_Select_OrdersPersonList
  122. as
  123. with p as
  124. (
  125. select max(Ordpg_Number) as Ordpg_Number,Ordpg_ViceNumber,
  126. dbo.AggregateString(Ordpg_Sights+'{$$},{$$}s') as Ordpg_Sights,
  127. dbo.AggregateString(Ordpg_Photographer+'{$$},{$$}s') as Ordpg_Photographer,
  128. max(Ordpg_PhotographyTime) as Ordpg_PhotographyTime,
  129. (case when (sum(CONVERT(int,Ordpg_PhotographyStatus)))=(count(1)) then 1 else 0 end) as PhotographyStatus,
  130. --dbo.AggregateString(Ordpg_PhotographyAssistant+'{$$},{$$}s') as Ordpg_PhotographyAssistant,
  131. --dbo.AggregateString(Ordpg_MakeupArtist+'{$$},{$$}s') as Ordpg_MakeupArtist,
  132. --dbo.AggregateString(Ordpg_MakeupAssistant+'{$$},{$$}s') as Ordpg_MakeupAssistant,
  133. --dbo.AggregateString(Ordpg_BootDivision+'{$$},{$$}s') as Ordpg_BootDivision,
  134. --dbo.AggregateString(Ordpg_BootDivisionAssistant+'{$$},{$$}s') as Ordpg_BootDivisionAssistant
  135. from dbo.tb_ErpOrdersPhotography
  136. group by Ordpg_ViceNumber
  137. ),
  138. t as
  139. (
  140. select OrdPe_OrderNumber, dbo.AggregateString([OrdPe_OrdersPerson]+'{$$},{$$}s') as OrdPe_OrdersPerson from dbo.tb_ErpOrdersPerson
  141. group by OrdPe_OrderNumber
  142. )
  143. select Ord_DividedShop,Ord_Number,Ordv_ViceNumber,Ordpg_Sights,Ord_SinceOrderNumber,Ord_Mc_Number,Ord_Type,Ord_Class,Ord_OrderClass,Ord_PhotographyCategory,Ord_SeriesName,Ord_SeriesPrice,Ord_PackageName,Ord_PackagePrice,Ord_CreateDateTime
  144. ,OrdPe_OrdersPerson
  145. ,Ordv_DigitalNumber,Ordv_ClothingStatus,Ordv_ClothingName,
  146. Ordv_ClothingTime,Ordv_EarlyRepairName,Ordv_EarlyRepairTime,ordv_EarlyRepairStatus,
  147. Ordv_FilmSelectionName,Ordv_FilmSelectionTime,Ordv_FilmSelectionStatus,Ordv_DesignerName,
  148. Ordv_DesignerTime,Ordv_DesignerStatus,Ordv_RefinementName,Ordv_RefinementTime,Ordv_RefinementStatus,
  149. Ordv_LookDesignName,Ordv_LookDesignTime,Ordv_LookDesignStatus
  150. ,Ordpg_Photographer,Ordpg_PhotographyTime,PhotographyStatus,Ordpg_PhotographyAssistant,Ordpg_MakeupArtist
  151. ,Ordpg_MakeupAssistant,Ordpg_BootDivision,Ordpg_BootDivisionAssistant
  152. from dbo.tb_ErpOrder
  153. left join t on Ord_Number= OrdPe_OrderNumber
  154. left join dbo.tb_ErpOrderDigital on Ord_Number=Ordv_Number
  155. left join p on Ordv_ViceNumber=Ordpg_ViceNumber
  156. where Ord_Class=1
  157. GO
  158. select * from [dbo].[vw_Select_OrdersPersonList]
  159. where PhotographyStatus=1 and (OrdPe_OrdersPerson like '%四%' or Ordpg_Sights like '%四%' or Ord_OrderClass like '%四%' or Ord_PhotographyCategory like '%四%' or Ord_SeriesName like '%四%' or Ord_SeriesPrice like '%四%' )--ord_number='ET15102900001'
  160. /*IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_Select_OrdersPersonList]'))
  161. DROP VIEW [dbo].[vw_Select_OrdersPersonList]
  162. GO
  163. CREATE VIEW dbo.vw_Select_OrdersPersonList
  164. WITH SCHEMABINDING
  165. as
  166. select OrdPe_OrderNumber, dbo.FunTrim(dbo.AggregateString([OrdPe_OrdersPerson]+'{$$},{$$}s'),'/') as OrdPe_OrdersPerson from dbo.tb_ErpOrdersPerson
  167. group by OrdPe_OrderNumber
  168. GO*/
  169. --下面的脚本给我们的视图建立索引:
  170. --CREATE UNIQUE CLUSTERED INDEX
  171. --idx_OrdersPersonListView ON vw_Index_OrdersPersonList(OrdPe_OrderNumber)
  172. --8大时间查询
  173. --订单信息
  174. --联合查询
  175. Declare @OrdersPerson varchar(max);
  176. with ord as(
  177. --订单时间
  178. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  179. UNION
  180. --拍照时间
  181. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  182. UNION
  183. --初修时间
  184. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  185. UNION
  186. --精修时间
  187. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  188. UNION
  189. --设计修时间
  190. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  191. UNION
  192. --选片时间
  193. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  194. UNION
  195. --取件时间
  196. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  197. UNION
  198. --收款时间
  199. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  200. ),
  201. orderList as
  202. (
  203. select top 10000 ordNumber from ord where RDateTime>='2016-01-01' and RDateTime<'2016-03-01' group by ordNumber
  204. )
  205. --select @OrdersPerson=isnull(@OrdersPerson,'''0''')+','''+ cast(ordNumber as nvarchar(20))+'''' from orderList
  206. --select @OrdersPerson
  207. ,
  208. p as
  209. (
  210. select max(Ordpg_Number) as Ordpg_Number,Ordpg_ViceNumber,
  211. dbo.AggregateString(Ordpg_Sights+'{$$},{$$}s') as Ordpg_Sights,
  212. dbo.AggregateString(Ordpg_SightsLevel+'{$$},{$$}s') as Ordpg_SightsLevel,
  213. dbo.AggregateString(Ordpg_Photographer+'{$$},{$$}s') as Ordpg_Photographer,
  214. max(Ordpg_PhotographyTime) as Ordpg_PhotographyTime,
  215. (case when (sum(CONVERT(int,Ordpg_PhotographyStatus)))=(count(1)) then 1 else 0 end) as PhotographyStatus,
  216. dbo.AggregateString(Ordpg_PhotographyAssistant+'{$$},{$$}s') as Ordpg_PhotographyAssistant,
  217. dbo.AggregateString(Ordpg_MakeupArtist+'{$$},{$$}s') as Ordpg_MakeupArtist,
  218. dbo.AggregateString(Ordpg_MakeupAssistant+'{$$},{$$}s') as Ordpg_MakeupAssistant,
  219. dbo.AggregateString(Ordpg_BootDivision+'{$$},{$$}s') as Ordpg_BootDivision,
  220. dbo.AggregateString(Ordpg_BootDivisionAssistant+'{$$},{$$}s') as Ordpg_BootDivisionAssistant
  221. from dbo.tb_ErpOrdersPhotography
  222. group by Ordpg_ViceNumber
  223. ),
  224. t as
  225. (
  226. select OrdPe_OrderNumber, dbo.AggregateString([OrdPe_OrdersPerson]+'{$$},{$$}s') as OrdPe_OrdersPerson from dbo.tb_ErpOrdersPerson
  227. group by OrdPe_OrderNumber
  228. )
  229. select Ord_DividedShop,Ord_Number,Ordv_ViceNumber,Ordpg_Sights,Ordpg_SightsLevel,Ord_SinceOrderNumber,Ord_Type,Ord_Class,Ord_OrderClass,Ord_PhotographyCategory,Ord_SeriesName,Ord_SeriesPrice,Ord_CreateDateTime
  230. ,OrdPe_OrdersPerson
  231. ,Ordv_DigitalNumber
  232. ,Ordv_EarlyRepairName,Ordv_EarlyRepairTime,ordv_EarlyRepairStatus,
  233. Ordv_FilmSelectionName,Ordv_FilmSelectionTime,Ordv_FilmSelectionStatus,Ordv_DesignerName,
  234. Ordv_DesignerTime,Ordv_DesignerStatus,Ordv_RefinementName,Ordv_RefinementTime,Ordv_RefinementStatus,
  235. Ordv_LookDesignName,Ordv_LookDesignTime,Ordv_LookDesignStatus
  236. ,Ordpg_Photographer,Ordpg_PhotographyTime,PhotographyStatus,Ordpg_PhotographyAssistant,Ordpg_MakeupArtist
  237. ,Ordpg_MakeupAssistant,Ordpg_BootDivision,Ordpg_BootDivisionAssistant
  238. ,[GP_CustomerSource],[Cus_Name]
  239. ,[dbo].[fun_GetPickupStatusStatus]([OPlist_PickupStatus],productCount) AS PickupStatus,[OPlist_PickupTime]
  240. from dbo.tb_ErpOrder
  241. left join t on Ord_Number= OrdPe_OrderNumber
  242. left join dbo.tb_ErpOrderDigital on Ord_Number=Ordv_Number
  243. left join p on Ordv_ViceNumber=Ordpg_ViceNumber
  244. left join [dbo].[Vw_OrderProductPickupView] on Ordv_ViceNumber=OPlist_ViceNumber
  245. left join [dbo].[tempTB_AggregationCustomer] on Ord_Number=[GP_OrderNumber]
  246. where Ord_Class=1 and Ord_Number in(select ordNumber from orderList)
  247. --当前时间段的订单数
  248. with ord as(
  249. --订单时间
  250. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  251. UNION
  252. --拍照时间
  253. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  254. UNION
  255. --初修时间
  256. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  257. UNION
  258. --精修时间
  259. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  260. UNION
  261. --设计修时间
  262. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  263. UNION
  264. --选片时间
  265. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  266. UNION
  267. --取件时间
  268. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  269. UNION
  270. --收款时间
  271. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  272. ),
  273. orderList as
  274. (
  275. select ordNumber from ord where RDateTime>='2015-01-01' and RDateTime<'2016-03-01' group by ordNumber
  276. )
  277. select Ord_Type,count(1) as sumCount from dbo.tb_ErpOrder where Ord_Class=1 and Ord_Number in(select ordNumber from orderList) group by Ord_Type
  278. --当前时间段相关的所有订单数
  279. select Ord_Type,count(1) as sumCount from dbo.tb_ErpOrder where Ord_Class=1 and Ord_CreateDateTime>='2016-01-01' and Ord_CreateDateTime<'2016-03-01' group by Ord_Type
  280. --获取订单拍摄景点和阶段等级统计信息
  281. --联合查询
  282. with ord as(
  283. --订单时间
  284. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  285. UNION
  286. --拍照时间
  287. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  288. UNION
  289. --初修时间
  290. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  291. UNION
  292. --精修时间
  293. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  294. UNION
  295. --设计修时间
  296. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  297. UNION
  298. --选片时间
  299. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  300. UNION
  301. --取件时间
  302. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  303. UNION
  304. --收款时间
  305. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  306. ),
  307. orderList as
  308. (
  309. select ordNumber from ord where RDateTime>='2016-01-01' and RDateTime<'2016-03-01' group by ordNumber
  310. )
  311. select Ordpg_Number,
  312. dbo.AggregateString(Ordpg_SightsLevel+'{$$},{$$}s') as Ordpg_SightsLevel
  313. ,count(1) as sumCount
  314. from dbo.tb_ErpOrdersPhotography
  315. where Ordpg_Number in(select ordNumber from orderList)
  316. group by Ordpg_Number
  317. --获取订单拍摄景点和阶段人员统计信息
  318. --联合查询
  319. with ord as(
  320. --订单时间
  321. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  322. UNION
  323. --拍照时间
  324. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  325. UNION
  326. --初修时间
  327. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  328. UNION
  329. --精修时间
  330. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  331. UNION
  332. --设计修时间
  333. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  334. UNION
  335. --选片时间
  336. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  337. UNION
  338. --取件时间
  339. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  340. UNION
  341. --收款时间
  342. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  343. ),
  344. orderList as
  345. (
  346. select ordNumber from ord where RDateTime>='2016-01-01' and RDateTime<'2016-03-01' group by ordNumber
  347. )
  348. select Ordpg_Number,Ordpg_ViceNumber,
  349. Ordpg_Sights,
  350. Ordpg_SightsLevel,
  351. Ordpg_Photographer,
  352. Ordpg_PhotographyTime,
  353. Ordpg_PhotographyStatus,
  354. Ordpg_PhotographyAssistant,
  355. Ordpg_MakeupArtist,
  356. Ordpg_MakeupAssistant,
  357. Ordpg_BootDivision,
  358. Ordpg_BootDivisionAssistant
  359. from dbo.tb_ErpOrdersPhotography
  360. where Ordpg_Number in(select ordNumber from orderList)
  361. --订单收款记录
  362. with ord as(
  363. --订单时间
  364. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  365. UNION
  366. --拍照时间
  367. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  368. UNION
  369. --初修时间
  370. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  371. UNION
  372. --精修时间
  373. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  374. UNION
  375. --设计修时间
  376. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  377. UNION
  378. --选片时间
  379. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  380. UNION
  381. --取件时间
  382. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  383. UNION
  384. --收款时间
  385. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  386. )
  387. select Pay_OrdNumber,
  388. Pay_ViceNumber,
  389. Pay_ShootingName,
  390. Pay_Category,
  391. Pay_TwoPinsCategory,
  392. (Pay_AmountOf - Pay_DiscountAmount) as PaidAmount,
  393. Pay_AmountOf,
  394. Pay_PaymentDiscount,
  395. Pay_DiscountAmount,
  396. Pay_OpenSingle,
  397. Pay_CreateName,
  398. Pay_Type,
  399. Pay_DividedShop,
  400. Pay_PaymentMethod,
  401. Pay_ReceivableProject,
  402. Pay_CreateDatetime from [dbo].[tb_ErpPayment] where Pay_Type =0
  403. and Pay_OrdNumber in(select ordNumber from ord where RDateTime>='2016-01-01' and RDateTime<'2016-02-01' group by ordNumber)
  404. --礼服租售订单表
  405. select
  406. Dsro_Number,
  407. Dsro_Type,
  408. Dsro_Amount,
  409. Dsro_CustomerNumber,
  410. Cus_Name,
  411. Dsro_CreateDateTime,
  412. Dsro_CreateName,
  413. Dsro_DividedShop,
  414. Pay_Category,
  415. (Pay_AmountOf - Pay_DiscountAmount) as PaidAmount,
  416. Pay_AmountOf,
  417. Pay_PaymentDiscount,
  418. Pay_DiscountAmount,
  419. Pay_OpenSingle,
  420. Pay_ThePayee,
  421. Pay_Type,
  422. Pay_DividedShop,
  423. Pay_PaymentMethod,
  424. Pay_ReceivableProject,
  425. Pay_CreateDatetime
  426. from tb_ErpDressSaleRentalOrder
  427. left join dbo.tb_ErpCustomer on Dsro_CustomerNumber=Cus_CustomerNumber
  428. left join [dbo].[tb_ErpPayment] on Dsro_Number=Pay_OrdNumber
  429. where Dsro_Type<2 and Pay_Type =2 and Pay_CreateDatetime>='2016-09-01' and Pay_CreateDatetime<'2016-11-01'
  430. --其它销费
  431. select Tsorder_Number,Tsorder_Name,Tsorder_Money,Tsorder_Quantity,Tsorder_Category,Tsorder_OpenSingle
  432. ,Tsorder_CustomerNumber,Cus_Name,Tsorder_CreateDatetime,Tsorder_DividedShop,
  433. Pay_Category,
  434. (Pay_AmountOf - Pay_DiscountAmount) as PaidAmount,
  435. Pay_AmountOf,
  436. Pay_PaymentDiscount,
  437. Pay_DiscountAmount,
  438. Pay_OpenSingle,
  439. Pay_ThePayee,
  440. Pay_Type,
  441. Pay_DividedShop,
  442. Pay_PaymentMethod,
  443. Pay_ReceivableProject,
  444. Pay_CreateDatetime
  445. from tb_ErpTwoSalesOrder
  446. left join [dbo].[tb_ErpPayment] on Tsorder_Number=Pay_OrdNumber
  447. left join tb_ErpCustomer on Tsorder_CustomerNumber=Cus_CustomerNumber
  448. where Pay_Type =1 and Pay_CreateDatetime>='2015-09-01' and Pay_CreateDatetime<'2016-11-30'
  449. --计件提成金额查询记录
  450. with WageCommissionSet as
  451. (
  452. SELECT [Wcs_TypeCode]
  453. ,[Wcs_Percentage]
  454. FROM [dbo].[tb_ErpWageCommissionSet]
  455. where [Wcs_Type]='计件式提成'
  456. )
  457. select Pcr_OrderNumber,
  458. Pcr_DigitalDivision ,
  459. Pcr_Date ,
  460. Pcr_CompletionContents,
  461. (Wcs_Percentage * Pcr_Quantity) as sum_Percentage,
  462. Pcr_Quantity ,
  463. Pcr_Type ,
  464. --Pcr_MarkKey ,
  465. Pcr_CreateTime,
  466. Pcr_EntryPeople ,
  467. Pcr_DividedShop
  468. from tb_ErpPieceCommissionRecords
  469. left join WageCommissionSet on Pcr_CompletionContents=[Wcs_TypeCode]
  470. where Pcr_CreateTime>='2016-09-01' and Pcr_CreateTime<'2016-11-01'
  471. select * from [tb_ErpWageCommissionSet] where [Wcs_Type]='计件式提成'
  472. --会员卡充值
  473. with cTb as
  474. (
  475. select Mc_Number,Mc_CradNumber,Cus_Name,Mc_CustomerNumber,Mc_CardType from dbo.tb_ErpMemberCard
  476. left join dbo.tb_ErpCustomer on Mc_CustomerNumber=Cus_CustomerNumber
  477. where len(Mc_CradNumber)>0
  478. )
  479. select
  480. Mcrr_Number,
  481. Mc_CradNumber,Cus_Name,Mc_CustomerNumber,Mc_CardType,
  482. Mcrr_RechargeNumber,
  483. Mcrr_RechargeName,
  484. Mcrr_RechargeAmount,
  485. Mcrr_DonateAmount,
  486. Mcrr_DonateDiscount,
  487. Mcrr_PaymentMethod,
  488. Mcrr_OrderPerson,
  489. Mcrr_CreateDatetime ,
  490. Mcrr_CreateName,
  491. Mcrr_DividedShop
  492. from tb_ErpMemberCardRechargeRecord
  493. left join cTb on Mcrr_Number=Mc_Number
  494. where Mcrr_CreateDatetime>='2016-09-01' and Mcrr_CreateDatetime<'2016-11-01'
  495. --会员服务卡收款表
  496. with cTb as
  497. (
  498. select Mc_Number,Mc_CradNumber,Cus_Name,Mc_CustomerNumber,Mc_CardType from dbo.tb_ErpMemberCard
  499. left join dbo.tb_ErpCustomer on Mc_CustomerNumber=Cus_CustomerNumber
  500. where len(Mc_CradNumber)>0
  501. )
  502. select
  503. Mc_CradNumber,Cus_Name,Mc_CustomerNumber,Mc_CardType,
  504. Mcpt_PaymentNumber,
  505. Mcpt_Number ,
  506. Mcpt_PaymentType,
  507. Mcpt_PaymentAmount,
  508. Mcpt_PaymentMethod,
  509. Mcpt_PackageClass,
  510. Mcpt_PackagePrice,
  511. Mcpt_Discount,
  512. Mcpt_DiscountAmount,
  513. Mcpt_OrderPerson,
  514. Mcpt_CreateDatetime,
  515. Mcpt_CreateName,
  516. Mcpt_DividedShop
  517. from tb_ErpMemberCardPayment
  518. left join cTb on Mcpt_Number=Mc_Number
  519. where Mcpt_CreateDatetime>='2015-01-01' and Mcpt_CreateDatetime<'2016-11-01'
  520. --满意度分值查询
  521. --满意分值统计
  522. -- select * from tb_ErpSatisfactionSurvey where Sfs_Type=0 --门市满意分值
  523. --select * from tb_ErpSatisfactionSurvey where Sfs_Type>0 and Sfs_Type<7 --其它流程满意分值 and Sfs_SurveySetID=7 --Sfs_SurveySetID=9
  524. --联合查询
  525. with ord as(
  526. --订单时间
  527. select Ord_Number as ordNumber,Ord_CreateDateTime as RDateTime from dbo.tb_ErpOrder where Ord_Class=1
  528. UNION
  529. --拍照时间
  530. select Ordpg_Number as ordNumber,max(Ordpg_PhotographyTime) as RDateTime from dbo.tb_ErpOrdersPhotography where Ordpg_PhotographyTime>0 group by Ordpg_Number
  531. UNION
  532. --初修时间
  533. select Ordv_Number as ordNumber,max(Ordv_EarlyRepairTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_EarlyRepairTime>0 group by Ordv_Number
  534. UNION
  535. --精修时间
  536. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  537. UNION
  538. --设计修时间
  539. select Ordv_Number as ordNumber,max(Ordv_DesignerTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_DesignerTime>0 group by Ordv_Number
  540. UNION
  541. --选片时间
  542. select Ordv_Number as ordNumber,max(Ordv_FilmSelectionTime) as RDateTime from dbo.tb_ErpOrderDigital where Ordv_FilmSelectionTime>0 group by Ordv_Number
  543. UNION
  544. --取件时间
  545. select OPlist_OrderNumber as ordNumber, max(OPlist_PickupTime) as RDateTime from [tb_ErpOrderProductList] where OPlist_Type =2 and OPlist_PickupTime>0 group by OPlist_OrderNumber
  546. UNION
  547. --收款时间
  548. select Pay_OrdNumber as ordNumber,Pay_CreateDatetime as RDateTime from [dbo].[tb_ErpPayment] where Pay_Type =0
  549. ),
  550. orderList as
  551. (
  552. select ordNumber from ord where RDateTime>='2016-10-01' and RDateTime<'2016-11-01' group by ordNumber
  553. )
  554. --门市
  555. select Sfs_OrderNumber,'' as Sfs_OrderNumberDeputy,
  556. (sum(Sfrs_Scores)/count(1)) as sumScores
  557. ,max(Sfss_MarkID) as MarkID
  558. from tb_ErpSatisfactionSurvey
  559. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  560. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.id
  561. where Sfs_Type=0 and Sfs_OrderNumber in (select ordNumber from orderList)
  562. group by Sfs_OrderNumber
  563. union
  564. --其它流程
  565. select max(Sfs_OrderNumber) as Sfs_OrderNumber,Sfs_OrderNumberDeputy,
  566. (sum(Sfrs_Scores)/count(1)) as sumScores
  567. ,max(Sfss_MarkID) as MarkID
  568. from tb_ErpSatisfactionSurvey
  569. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  570. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.id
  571. where (len(Sfs_OrderNumberDeputy)>0 and Sfs_Type>0 and Sfs_Type<7) and Sfs_OrderNumber in (select ordNumber from orderList)
  572. group by Sfs_OrderNumberDeputy