taihao

db.inpatient_fee_detail.aggregate([{‘$match‘ : {‘fee.date‘ : {‘$gte‘:ISODate("2016-03-10T12:39:50.676Z"), ‘$lte‘ : ISODate("2016-07-10T12:39:50.676Z")}}},
{‘$group‘ : {
‘_id‘: {
‘dept_id‘:‘$recipe_dept.id‘,
‘dept_name‘:‘$recipe_dept.name‘,
‘rpt_date‘:{‘$dateToString‘:{‘format‘:‘%Y%m%d‘,‘date‘:‘$fee.date‘}}
}
, ‘rpt_year‘: { ‘$first‘: {‘$substr‘:[{‘$year‘:‘$fee.date‘},0,4]} }
, ‘rpt_month‘: { ‘$first‘: {‘$dateToString‘:{‘format‘:‘%Y%m‘,‘date‘:‘$fee.date‘}} }
, ‘rpt_quarter‘: { ‘$first‘: {‘$concat‘: [ {‘$substr‘:[{‘$year‘:‘$fee.date‘},0,4]},{‘$substr‘:[{‘$ceil‘:{‘$divide‘:[{‘$month‘:‘$fee.date‘},3]}},0,2]}]}}
, ‘total_fee‘: {‘$sum‘: ‘$cost.total‘}
, ‘med_fee‘:{
‘$sum‘:{
‘$cond‘:[{
‘$or‘:[
{‘$eq‘:[‘$fee.id‘,‘61‘]},
{‘$eq‘:[‘$fee.id‘,‘71‘]},
{‘$eq‘:[‘$fee.id‘,‘72‘]}]},
‘$cost.total‘,0]}}
,‘material_fee‘:{
‘$sum‘:{
‘$cond‘:[{‘$eq‘:[‘$fee.id‘,‘9‘]},
‘$cost.total‘,0]}}
}}],{allowDiskUse:true})

时间: 10-29