123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- update apisql
- set sqlstr =
- "select
- '现代牧业' pastureName,
- 20 sort,
- #RIGHT(rr.wmonth,2) num,
- '设备指标(万元)' ftype,
- ROUND(sum(rr.monthBudget), 2) monthBudget,
- #预算
- ROUND(sum(rr.monthLimit), 2) monthLimit,
- #内控
- ROUND(sum(rr.sumPrice), 2) sumPrice,
- #迄今实际
- ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)), 2) asave,
- #实际节约
- ifnull(ROUND(1 +(( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.monthLimit)/ rr.sumDay * rr.realDay)), 2), 0) realReason,
- #实际达成率
- IFNULL(ROUND(sum(rr.monthBudget)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowBudget,
- #单头牛预算
- -- IFNULL(ROUND(sum(rr.monthLimit)/sum(rr.cowSumBudgetMonth),2),0) oneCowLimit, #单头牛内控
- sum(rr.oneCowLimit) oneCowLimit,
- -- IFNULL(ROUND((sum(rr.monthLimit)/rr.sumDay*rr.realDay)/(sum(rr.cowSumBudgetMonth)/rr.sumDay*rr.realDay),2),0) oneCowQmonthBudget,
- sum(rr.oneCowQmonthBudget) oneCowQmonthBudget,
- #单头牛迄今内控
- sum(rr.oneCowSumPrice) oneCowSumPrice,
- -- IFNULL(ROUND(sum(rr.sumPrice)/(sum(rr.cowSum)/rr.sumDay*rr.realDay),2),0) oneCowSumPrice,#单头牛的迄今实际
- -- IFNULL(ROUND((sum(rr.monthLimit)/rr.sumDay*rr.realDay-(sum(rr.sumPrice)))/(sum(rr.cowSum)/rr.sumDay*rr.realDay),2),0) oneCowAsave,
- sum(rr.oneCowAsave)oneCowAsave,
- 18 pastureId
- from
- (
- -- lag11
- select
- '维修费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSumBudgetMonth,
- qq.cowSum
- from
- (
- select
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '维修费' and (select iscal from department d where d.id = month_budget.`deptId`)= 0), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '维修费' and (select iscal from department d where d.id = month_budget.`deptId`)= 0 ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and (select iscal from department d where d.id = month_budget.`deptId`)= 0 ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- ROUND(IFNULL(SUM( pu.`sumPrice` - pu.`quitNumber` * pu.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- partuse pu
- inner join bigpartuse bpu
- on
- pu.`bigId` = bpu.`id`
- where
- bpu.`useType` <> 3
- and bpu.`receiveTime` >= CONCAT(DATE_FORMAT(DATE_ADD(?, interval -1 day), '%Y-%m'), '-01')
- and bpu.`receiveTime` < CONCAT(DATE_FORMAT(DATE_ADD(DATE_ADD(?, interval -1 day), interval 1 year), '%Y-%m'), '-01')
- and (
- pu.`useTypeV` = '维修'
- or pu.`useTypeV` = '保养'
- )
- and (
- select
- iscal
- from
- department d
- where
- d.id = bpu.`departmentId`)= 0
- ) tem) qq
- union all
- -- lag12
- select
- '电费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSum,
- qq.cowSumBudgetMonth
- from
- (
- select
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费'), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- ROUND(IFNULL(SUM(e.elecConsumption * e.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- electricity e
- inner join `measure` m
- on
- m.id = e.measureId
- where
- m.meterType = '电表'
- and m.useType = '2级表'
- and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
-
- ) tem) qq
- union all
- -- lag13
- select
- '水费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSum,
- qq.cowSumBudgetMonth
- from
- (
- select
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费'), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- ROUND(IFNULL(SUM(e.waterConsumption * e.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- water e
- inner join `measure` m
- on
- m.id = e.measureId
- where
- m.meterType = '水表'
- and m.useType = '2级表'
- and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
-
- ) tem) qq
- union all
- -- lag14
- select
- '燃动费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSum,
- qq.cowSumBudgetMonth
- from
- (
- select
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费'), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- ROUND(IFNULL(SUM(d.oilAmount * d.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- `diesel` d
- where
- d.selTime >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and d.selTime < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
-
- ) tem) qq) rr
- union all
- -- lag21
- select
- p.name,
- p.sort,
- '设备指标(万元)' ftype,
- ROUND(sum(rr.monthBudget), 2) monthBudget,
- #预算
- ROUND(sum(rr.monthLimit), 2) monthLimit,
- #内控
- ROUND(sum(rr.sumPrice), 2) sumPrice,
- #迄今实际
- ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)), 2) asave,
- #实际节约
- ifnull(ROUND(1 +(( sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.monthLimit)/ rr.sumDay * rr.realDay)), 2), 0) realReason,
- #实际达成率
- IFNULL(ROUND(sum(rr.monthBudget)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(sum(rr.monthLimit)/ sum(rr.cowSumBudgetMonth), 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((sum(rr.monthLimit)/ rr.sumDay * rr.realDay)/(sum(rr.cowSumBudgetMonth)/ rr.sumDay * rr.realDay), 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(sum(rr.sumPrice)/(sum(rr.cowSum)/ rr.sumDay * rr.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((sum(rr.monthLimit)/ rr.sumDay * rr.realDay-(sum(rr.sumPrice)))/(sum(rr.cowSum)/ rr.sumDay * rr.realDay), 2), 0) oneCowAsave,
- pastureId
- from
- (
- select
- '维修费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSum / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSumBudgetMonth,
- qq.cowSum,
- qq.pastureId
- from
- (
- select
- tem.pastureId,
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- 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,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- 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,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- 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,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- bpu.pastureId,
- ROUND(IFNULL(SUM( pu.`sumPrice` - pu.`quitNumber` * pu.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- partuse pu
- inner join bigpartuse bpu
- on
- pu.`bigId` = bpu.`id`
- where
- bpu.`useType` <> 3
- and bpu.`receiveTime` >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and bpu.`receiveTime` < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
- and (
- pu.`useTypeV` = '维修'
- or pu.`useTypeV` = '保养'
- )
- and (
- select
- iscal
- from
- department d
- where
- d.id = bpu.`departmentId`)= 0
- and (bpu.pastureId = ?
- or ? in ('18', ''))
- and (bpu.departmentId = ?
- or ? = '')
- group by
- bpu.pastureId ) tem) qq
- union all
- -- lag22
- select
- '电费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSumBudgetMonth,
- qq.cowSum,
- qq.pastureId
- from
- (
- select
- tem.pastureId,
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' and pastureId = tem.pastureId), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '电费' and pastureId = tem.pastureId ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- m.pastureId,
- ROUND(IFNULL(SUM(e.elecConsumption * e.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- electricity e
- inner join `measure` m
- on
- m.id = e.measureId
- where
- m.meterType = '电表'
- and m.useType = '2级表'
- and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
- and (m.pastureId = ?
- or ? in ('18', ''))
- and (m.departmentId = ?
- or ? = '')
- group by
- m.pastureId ) tem) qq
- union all
- -- lag23
- select
- '水费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSumBudgetMonth,
- qq.cowSum,
- qq.pastureId
- from
- (
- select
- tem.pastureId,
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' and pastureId = tem.pastureId), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '水费' and pastureId = tem.pastureId ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- m.pastureId,
- ROUND(IFNULL(SUM(e.waterConsumption * e.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- water e
- inner join `measure` m
- on
- m.id = e.measureId
- where
- m.meterType = '水表'
- and m.useType = '2级表'
- and e.date >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and e.date < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
- and (m.pastureId = ?
- or ? in ('18', ''))
- and (m.departmentId = ?
- or ? = '')
- group by
- m.pastureId ) tem) qq
- union all
- -- lag24
- select
- '燃动费(万元)' ftype,
- ROUND(qq.monthBudget, 2) monthBudget,
- #预算
- ROUND(qq.monthLimit, 2) monthLimit,
- #内控
- ROUND(qq.sumPrice / 10000, 2) sumPrice,
- #迄今实际
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay, 2) qmonthBudget,
- #迄今内控
- ROUND( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000), 2) asave,
- #实际节约
- ROUND(1 +(( qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice / 10000))/(qq.monthLimit / qq.sumDay * qq.realDay)), 2) realReason,
- #实际达成率
- IFNULL(ROUND(qq.monthBudget / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowBudget,
- #单头牛预算
- IFNULL(ROUND(qq.monthLimit / qq.cowSumBudgetMonth * 10000, 2), 0) oneCowLimit,
- #单头牛内控
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay)/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay)* 10000, 2), 0) oneCowQmonthBudget,
- #单头牛迄今内控
- IFNULL(ROUND(qq.sumPrice /(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowSumPrice,
- #单头牛的迄今实际
- IFNULL(ROUND((qq.monthLimit / qq.sumDay * qq.realDay-(qq.sumPrice))/(qq.cowSumBudgetMonth / qq.sumDay * qq.realDay), 2), 0) oneCowAsave,
- #单头牛迄今实际节约
- qq.sumDay,
- qq.realDay,
- qq.cowSumBudgetMonth,
- qq.cowSum,
- qq.pastureId
- from
- (
- select
- tem.pastureId,
- IFNULL((select SUM(monthBudget)monthBudget from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' and pastureId = tem.pastureId), 0)monthBudget,
- IFNULL((select SUM(monthLimit)monthLimit from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '燃动费' and pastureId = tem.pastureId ), 0)monthLimit,
- IFNULL((select SUM(monthBudget)cowSumBudgetMonth from `month_budget` where concat(budgetMonth, '-', '01') >= tem.startTime
- and concat(budgetMonth, '-', '01') < tem.endTime and feeType = '饲养头数月预算' and pastureId = tem.pastureId ), 0)cowSumBudgetMonth,
- 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,
- #DATEDIFF(DATE_ADD(LAST_DAY(tem.endTime),INTERVAL 1 DAY),tem.startTime) sumDay,#当前总天数
- #DATEDIFF(tem.endTime,tem.startTime) realDay,#到当前选择的天数
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1 sumDay,
- if (DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))= 0,
- DATEDIFF(LAST_DAY(tem.endTime), CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))+ 1,
- DATEDIFF(tem.endTime, CONCAT(DATE_FORMAT(tem.endTime, '%Y-%m'), '-01'))) realDay,
- tem.sumPrice
- from
- (
- select
- d.pastureId,
- ROUND(IFNULL(SUM(d.oilAmount * d.`price`), 0), 2) sumPrice,
- CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01') startTime,
- if(right(?,
- 2)= '00',
- CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01'),
- DATE_ADD(?, interval 1 day)) endTime
- from
- `diesel` d
- where
- d.selTime >= CONCAT(DATE_FORMAT(CONCAT(left(?, 7), '-01'), '%Y-%m'), '-01')
- and d.selTime < CONCAT(DATE_FORMAT(DATE_ADD(CONCAT(left(?, 7), '-01'), interval 1 month), '%Y-%m'), '-01')
- and (d.pastureId = ?
- or ? in ('18', ''))
- and (d.deptId = ?
- or ? = '')
- group by
- d.pastureId ) tem) qq
-
- ) rr
- inner join pasture p
- on
- p.id = rr.pastureId
- group by
- rr.pastureId
- order by
- sort"
- where sqlname ='getChooseEqMonthBudgetListSumAll'
|