SELECT jie.name as "所属街道",cen.name as "照料中心",cen.grade as "中心等级",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-1-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-1-31' ) as "1月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-2-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-2-28' ) as "2月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-3-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-3-31' ) as "3月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-4-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-4-30' ) as "4月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-5-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-5-31' ) as "5月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-6-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-6-30' ) as "6月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-7-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-7-31' ) as "7月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-8-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-8-31' ) as "8月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-9-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-9-30' ) as "9月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-10-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-10-31' ) as "10月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-11-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-11-30' ) as "11月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-12-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-12-31' ) as "12月订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-1-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-1-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-2-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-2-28' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-3-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-3-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-4-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-4-30' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-5-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-5-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-6-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-6-30' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-7-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-7-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-8-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-8-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-9-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-9-30' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-10-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-10-31' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-11-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-11-30' ) +
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref and cast(to_char(food.order_date,'YYYY-MM-DD') as date) >='2018-12-1' and cast(to_char(food.order_date,'YYYY-MM-DD') as date) <='2018-12-31' ) as "1-12月合计订餐数",
(select count(*) from food_order food where validity_flag='true' and cen.id=food.yanglaocenter_ref) as 累计订餐数
FROM yanglao_org_jiedao jie JOIN yanglao_org_yanglaocenter cen ON jie.id=cen.jiedao_ref
ORDER BY jie.name