getChooseEqMonthBudgetListSumAll.sql 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. update apisql
  2. set sqlstr =
  3. "select
  4. '现代牧业' pastureName,
  5. 20 sort,
  6. #RIGHT(rr.wmonth,2) num,
  7. '设备指标(万元)' ftype,
  8. ROUND(sum(rr.monthBudget), 2) monthBudget,
  9. #预算
  10. ROUND(sum(rr.monthLimit), 2) monthLimit,
  11. #内控
  12. ROUND(sum(rr.sumPrice), 2) sumPrice,
  13. #迄今实际
  14. ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay, 2) qmonthBudget,
  15. #迄今内控
  16. ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)), 2) asave,
  17. #实际节约
  18. ifnull(ROUND(1 +(( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.monthLimit)/ rr.sumDay * rr.realDay)), 2), 0) realReason,
  19. #实际达成率
  20. IFNULL(ROUND(sum(rr.monthBudget)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowBudget,
  21. #单头牛预算
  22. -- IFNULL(ROUND(sum(rr.monthLimit)/sum(rr.cowSumBudgetMonth),2),0) oneCowLimit, #单头牛内控
  23. sum(rr.oneCowLimit) oneCowLimit,
  24. -- IFNULL(ROUND((sum(rr.monthLimit)/rr.sumDay*rr.realDay)/(sum(rr.cowSumBudgetMonth)/rr.sumDay*rr.realDay),2),0) oneCowQmonthBudget,
  25. sum(rr.oneCowQmonthBudget) oneCowQmonthBudget,
  26. #单头牛迄今内控
  27. sum(rr.oneCowSumPrice) oneCowSumPrice,
  28. -- IFNULL(ROUND(sum(rr.sumPrice)/(sum(rr.cowSum)/rr.sumDay*rr.realDay),2),0) oneCowSumPrice,#单头牛的迄今实际
  29. -- IFNULL(ROUND((sum(rr.monthLimit)/rr.sumDay*rr.realDay-(sum(rr.sumPrice)))/(sum(rr.cowSum)/rr.sumDay*rr.realDay),2),0) oneCowAsave,
  30. sum(rr.oneCowAsave)oneCowAsave,
  31. 18 pastureId
  32. from
  33. (
  34. -- lag11
  35. select
  36. '维修费(万元)' ftype,
  37. ROUND(qq.monthBudget, 2) monthBudget,
  38. #预算
  39. ROUND(qq.monthLimit, 2) monthLimit,
  40. #内控
  41. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  42. #迄今实际
  43. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  44. #迄今内控
  45. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  46. #实际节约
  47. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  48. #实际达成率
  49. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  50. #单头牛预算
  51. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  52. #单头牛内控
  53. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  54. #单头牛迄今内控
  55. IFNULL(ROUND(qq.sumPrice /(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  56. #单头牛的迄今实际
  57. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  58. #单头牛迄今实际节约
  59. qq.sumDay,
  60. qq.realDay,
  61. qq.cowSumBudgetMonth,
  62. qq.cowSum
  63. from
  64. (
  65. select
  66. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  67. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '维修费' and (select iscal from department d where d.id = month_budget.`deptId`)= 0), 0)monthBudget,
  68. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  69. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '维修费' and (select iscal from department d where d.id = month_budget.`deptId`)= 0 ), 0)monthLimit,
  70. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  71. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and (select iscal from department d where d.id = month_budget.`deptId`)= 0 ), 0)cowSumBudgetMonth,
  72. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  73. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  74. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  75. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  76. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  77. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  78. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  79. tem.sumPrice
  80. from
  81. (
  82. select
  83. ROUND(IFNULL(SUM( pu.`sumPrice` - pu.`quitNumber` * pu.`price`), 0), 2) sumPrice,
  84. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  85. if(right(?,
  86. 2)= '00',
  87. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  88. DATE_ADD(?, interval 1 day)) endTime
  89. from
  90. partuse pu
  91. inner join bigpartuse bpu
  92. on
  93. pu.`bigId` = bpu.`id`
  94. where
  95. bpu.`useType` <> 3
  96. and bpu.`receiveTime` >= CONCAT(DATE_FORMAT(DATE_ADD(?, interval -1 day), '%Y-%m'), '-01')
  97. and bpu.`receiveTime` < CONCAT(DATE_FORMAT(DATE_ADD(DATE_ADD(?, interval -1 day), interval 1 year), '%Y-%m'), '-01')
  98. and (
  99. pu.`useTypeV` = '维修'
  100. or pu.`useTypeV` = '保养'
  101. )
  102. and (
  103. select
  104. iscal
  105. from
  106. department d
  107. where
  108. d.id = bpu.`departmentId`)= 0
  109. ) tem) qq
  110. union all
  111. -- lag12
  112. select
  113. '电费(万元)' ftype,
  114. ROUND(qq.monthBudget, 2) monthBudget,
  115. #预算
  116. ROUND(qq.monthLimit, 2) monthLimit,
  117. #内控
  118. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  119. #迄今实际
  120. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  121. #迄今内控
  122. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  123. #实际节约
  124. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  125. #实际达成率
  126. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  127. #单头牛预算
  128. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  129. #单头牛内控
  130. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  131. #单头牛迄今内控
  132. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  133. #单头牛的迄今实际
  134. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  135. #单头牛迄今实际节约
  136. qq.sumDay,
  137. qq.realDay,
  138. qq.cowSum,
  139. qq.cowSumBudgetMonth
  140. from
  141. (
  142. select
  143. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  144. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费'), 0)monthBudget,
  145. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  146. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' ), 0)monthLimit,
  147. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  148. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
  149. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  150. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  151. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  152. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  153. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  154. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  155. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  156. tem.sumPrice
  157. from
  158. (
  159. select
  160. ROUND(IFNULL(SUM(e.elecConsumption * e.`price`), 0), 2) sumPrice,
  161. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  162. if(right(?,
  163. 2)= '00',
  164. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  165. DATE_ADD(?, interval 1 day)) endTime
  166. from
  167. electricity e
  168. inner join `measure` m
  169. on
  170. m.id = e.measureId
  171. where
  172. m.meterType = '电表'
  173. and m.useType = '2级表'
  174. and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  175. and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  176. ) tem) qq
  177. union all
  178. -- lag13
  179. select
  180. '水费(万元)' ftype,
  181. ROUND(qq.monthBudget, 2) monthBudget,
  182. #预算
  183. ROUND(qq.monthLimit, 2) monthLimit,
  184. #内控
  185. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  186. #迄今实际
  187. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  188. #迄今内控
  189. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  190. #实际节约
  191. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  192. #实际达成率
  193. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  194. #单头牛预算
  195. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  196. #单头牛内控
  197. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  198. #单头牛迄今内控
  199. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  200. #单头牛的迄今实际
  201. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  202. #单头牛迄今实际节约
  203. qq.sumDay,
  204. qq.realDay,
  205. qq.cowSum,
  206. qq.cowSumBudgetMonth
  207. from
  208. (
  209. select
  210. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  211. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费'), 0)monthBudget,
  212. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  213. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' ), 0)monthLimit,
  214. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  215. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
  216. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  217. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  218. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  219. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  220. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  221. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  222. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  223. tem.sumPrice
  224. from
  225. (
  226. select
  227. ROUND(IFNULL(SUM(e.waterConsumption * e.`price`), 0), 2) sumPrice,
  228. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  229. if(right(?,
  230. 2)= '00',
  231. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  232. DATE_ADD(?, interval 1 day)) endTime
  233. from
  234. water e
  235. inner join `measure` m
  236. on
  237. m.id = e.measureId
  238. where
  239. m.meterType = '水表'
  240. and m.useType = '2级表'
  241. and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  242. and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  243. ) tem) qq
  244. union all
  245. -- lag14
  246. select
  247. '燃动费(万元)' ftype,
  248. ROUND(qq.monthBudget, 2) monthBudget,
  249. #预算
  250. ROUND(qq.monthLimit, 2) monthLimit,
  251. #内控
  252. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  253. #迄今实际
  254. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  255. #迄今内控
  256. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  257. #实际节约
  258. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  259. #实际达成率
  260. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  261. #单头牛预算
  262. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  263. #单头牛内控
  264. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  265. #单头牛迄今内控
  266. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  267. #单头牛的迄今实际
  268. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  269. #单头牛迄今实际节约
  270. qq.sumDay,
  271. qq.realDay,
  272. qq.cowSum,
  273. qq.cowSumBudgetMonth
  274. from
  275. (
  276. select
  277. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  278. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费'), 0)monthBudget,
  279. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  280. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' ), 0)monthLimit,
  281. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  282. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
  283. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  284. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  285. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  286. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  287. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  288. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  289. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  290. tem.sumPrice
  291. from
  292. (
  293. select
  294. ROUND(IFNULL(SUM(d.oilAmount * d.`price`), 0), 2) sumPrice,
  295. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  296. if(right(?,
  297. 2)= '00',
  298. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  299. DATE_ADD(?, interval 1 day)) endTime
  300. from
  301. `diesel` d
  302. where
  303. d.selTime >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  304. and d.selTime < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  305. ) tem) qq) rr
  306. union all
  307. -- lag21
  308. select
  309. p.name,
  310. p.sort,
  311. '设备指标(万元)' ftype,
  312. ROUND(sum(rr.monthBudget), 2) monthBudget,
  313. #预算
  314. ROUND(sum(rr.monthLimit), 2) monthLimit,
  315. #内控
  316. ROUND(sum(rr.sumPrice), 2) sumPrice,
  317. #迄今实际
  318. ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay, 2) qmonthBudget,
  319. #迄今内控
  320. ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)), 2) asave,
  321. #实际节约
  322. ifnull(ROUND(1 +(( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.monthLimit)/ rr.sumDay * rr.realDay)), 2), 0) realReason,
  323. #实际达成率
  324. IFNULL(ROUND(sum(rr.monthBudget)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowBudget,
  325. #单头牛预算
  326. IFNULL(ROUND(sum(rr.monthLimit)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowLimit,
  327. #单头牛内控
  328. IFNULL(ROUND((sum(rr.monthLimit)/ rr.sumDay * rr.realDay)/(sum(rr.cowSumBudgetMonth)/ rr.sumDay * rr.realDay), 2), 0) oneCowQmonthBudget,
  329. #单头牛迄今内控
  330. IFNULL(ROUND(sum(rr.sumPrice)/(sum(rr.cowSum)/ rr.sumDay * rr.realDay), 2), 0) oneCowSumPrice,
  331. #单头牛的迄今实际
  332. IFNULL(ROUND((sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.cowSum)/ rr.sumDay * rr.realDay), 2), 0) oneCowAsave,
  333. pastureId
  334. from
  335. (
  336. select
  337. '维修费(万元)' ftype,
  338. ROUND(qq.monthBudget, 2) monthBudget,
  339. #预算
  340. ROUND(qq.monthLimit, 2) monthLimit,
  341. #内控
  342. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  343. #迄今实际
  344. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  345. #迄今内控
  346. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  347. #实际节约
  348. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  349. #实际达成率
  350. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  351. #单头牛预算
  352. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  353. #单头牛内控
  354. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  355. #单头牛迄今内控
  356. IFNULL(ROUND(qq.sumPrice /(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  357. #单头牛的迄今实际
  358. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  359. #单头牛迄今实际节约
  360. qq.sumDay,
  361. qq.realDay,
  362. qq.cowSumBudgetMonth,
  363. qq.cowSum,
  364. qq.pastureId
  365. from
  366. (
  367. select
  368. tem.pastureId,
  369. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  370. and concat(budgetMonth, '-', '01') < tem.endTime and pastureId = tem.pastureId and feeType = '维修费' and pastureId = tem.pastureId and (select iscal from department d where d.id = month_budget.`deptId`)= 0), 0)monthBudget,
  371. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  372. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '维修费' and pastureId = tem.pastureId and (select iscal from department d where d.id = month_budget.`deptId`)= 0), 0)monthLimit,
  373. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  374. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId and (select iscal from department d where d.id = month_budget.`deptId`)= 0), 0)cowSumBudgetMonth,
  375. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where p.id = tem.pastureId and fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  376. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  377. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  378. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  379. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  380. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  381. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  382. tem.sumPrice
  383. from
  384. (
  385. select
  386. bpu.pastureId,
  387. ROUND(IFNULL(SUM( pu.`sumPrice` - pu.`quitNumber` * pu.`price`), 0), 2) sumPrice,
  388. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  389. if(right(?,
  390. 2)= '00',
  391. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  392. DATE_ADD(?, interval 1 day)) endTime
  393. from
  394. partuse pu
  395. inner join bigpartuse bpu
  396. on
  397. pu.`bigId` = bpu.`id`
  398. where
  399. bpu.`useType` <> 3
  400. and bpu.`receiveTime` >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  401. and bpu.`receiveTime` < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  402. and (
  403. pu.`useTypeV` = '维修'
  404. or pu.`useTypeV` = '保养'
  405. )
  406. and (
  407. select
  408. iscal
  409. from
  410. department d
  411. where
  412. d.id = bpu.`departmentId`)= 0
  413. and (bpu.pastureId = ?
  414. or ? in ('18', ''))
  415. and (bpu.departmentId = ?
  416. or ? = '')
  417. group by
  418. bpu.pastureId ) tem) qq
  419. union all
  420. -- lag22
  421. select
  422. '电费(万元)' ftype,
  423. ROUND(qq.monthBudget, 2) monthBudget,
  424. #预算
  425. ROUND(qq.monthLimit, 2) monthLimit,
  426. #内控
  427. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  428. #迄今实际
  429. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  430. #迄今内控
  431. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  432. #实际节约
  433. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  434. #实际达成率
  435. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  436. #单头牛预算
  437. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  438. #单头牛内控
  439. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  440. #单头牛迄今内控
  441. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  442. #单头牛的迄今实际
  443. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  444. #单头牛迄今实际节约
  445. qq.sumDay,
  446. qq.realDay,
  447. qq.cowSumBudgetMonth,
  448. qq.cowSum,
  449. qq.pastureId
  450. from
  451. (
  452. select
  453. tem.pastureId,
  454. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  455. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' and pastureId = tem.pastureId), 0)monthBudget,
  456. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  457. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' and pastureId = tem.pastureId ), 0)monthLimit,
  458. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  459. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
  460. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where p.id = tem.pastureId and fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  461. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  462. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  463. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  464. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  465. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  466. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  467. tem.sumPrice
  468. from
  469. (
  470. select
  471. m.pastureId,
  472. ROUND(IFNULL(SUM(e.elecConsumption * e.`price`), 0), 2) sumPrice,
  473. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  474. if(right(?,
  475. 2)= '00',
  476. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  477. DATE_ADD(?, interval 1 day)) endTime
  478. from
  479. electricity e
  480. inner join `measure` m
  481. on
  482. m.id = e.measureId
  483. where
  484. m.meterType = '电表'
  485. and m.useType = '2级表'
  486. and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  487. and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  488. and (m.pastureId = ?
  489. or ? in ('18', ''))
  490. and (m.departmentId = ?
  491. or ? = '')
  492. group by
  493. m.pastureId ) tem) qq
  494. union all
  495. -- lag23
  496. select
  497. '水费(万元)' ftype,
  498. ROUND(qq.monthBudget, 2) monthBudget,
  499. #预算
  500. ROUND(qq.monthLimit, 2) monthLimit,
  501. #内控
  502. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  503. #迄今实际
  504. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  505. #迄今内控
  506. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  507. #实际节约
  508. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  509. #实际达成率
  510. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  511. #单头牛预算
  512. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  513. #单头牛内控
  514. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  515. #单头牛迄今内控
  516. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  517. #单头牛的迄今实际
  518. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  519. #单头牛迄今实际节约
  520. qq.sumDay,
  521. qq.realDay,
  522. qq.cowSumBudgetMonth,
  523. qq.cowSum,
  524. qq.pastureId
  525. from
  526. (
  527. select
  528. tem.pastureId,
  529. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  530. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' and pastureId = tem.pastureId), 0)monthBudget,
  531. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  532. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' and pastureId = tem.pastureId ), 0)monthLimit,
  533. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  534. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
  535. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where p.id = tem.pastureId and fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  536. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  537. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  538. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  539. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  540. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  541. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  542. tem.sumPrice
  543. from
  544. (
  545. select
  546. m.pastureId,
  547. ROUND(IFNULL(SUM(e.waterConsumption * e.`price`), 0), 2) sumPrice,
  548. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  549. if(right(?,
  550. 2)= '00',
  551. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  552. DATE_ADD(?, interval 1 day)) endTime
  553. from
  554. water e
  555. inner join `measure` m
  556. on
  557. m.id = e.measureId
  558. where
  559. m.meterType = '水表'
  560. and m.useType = '2级表'
  561. and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  562. and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  563. and (m.pastureId = ?
  564. or ? in ('18', ''))
  565. and (m.departmentId = ?
  566. or ? = '')
  567. group by
  568. m.pastureId ) tem) qq
  569. union all
  570. -- lag24
  571. select
  572. '燃动费(万元)' ftype,
  573. ROUND(qq.monthBudget, 2) monthBudget,
  574. #预算
  575. ROUND(qq.monthLimit, 2) monthLimit,
  576. #内控
  577. ROUND(qq.sumPrice / 10000, 2) sumPrice,
  578. #迄今实际
  579. ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
  580. #迄今内控
  581. ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
  582. #实际节约
  583. ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
  584. #实际达成率
  585. IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
  586. #单头牛预算
  587. IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
  588. #单头牛内控
  589. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
  590. #单头牛迄今内控
  591. IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
  592. #单头牛的迄今实际
  593. IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
  594. #单头牛迄今实际节约
  595. qq.sumDay,
  596. qq.realDay,
  597. qq.cowSumBudgetMonth,
  598. qq.cowSum,
  599. qq.pastureId
  600. from
  601. (
  602. select
  603. tem.pastureId,
  604. IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  605. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' and pastureId = tem.pastureId), 0)monthBudget,
  606. IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  607. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' and pastureId = tem.pastureId ), 0)monthLimit,
  608. IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
  609. and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
  610. IFNULL((select sum(fs.`cowNum`) from feed_sum fs inner join pasture p on p.id = fs.pastureId where p.id = tem.pastureId and fs.`feedDay` >= tem.startTime and fs.`feedDay` <= tem.endTime), 0) cowSum,
  611. #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
  612. #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
  613. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
  614. if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
  615. DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
  616. DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
  617. tem.sumPrice
  618. from
  619. (
  620. select
  621. d.pastureId,
  622. ROUND(IFNULL(SUM(d.oilAmount * d.`price`), 0), 2) sumPrice,
  623. CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
  624. if(right(?,
  625. 2)= '00',
  626. CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
  627. DATE_ADD(?, interval 1 day)) endTime
  628. from
  629. `diesel` d
  630. where
  631. d.selTime >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
  632. and d.selTime < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
  633. and (d.pastureId = ?
  634. or ? in ('18', ''))
  635. and (d.deptId = ?
  636. or ? = '')
  637. group by
  638. d.pastureId ) tem) qq
  639. ) rr
  640. inner join pasture p
  641. on
  642. p.id = rr.pastureId
  643. group by
  644. rr.pastureId
  645. order by
  646. sort"
  647. where sqlname ='getChooseEqMonthBudgetListSumAll'