我写过的最长的SQL语句
童学芬 2016-03-23 10:43

你见最长的sql语句有多长?

SELECT t.Month,t.total as 'All',case when t10.total is null then 0 else t10.total end as 'Mattress',case when t11.total is null then 0 else t11.total end as 'Showwood',case when t12.total is null then 0 else t12.total end as 'Accent Chair',case when t13.total is null then 0 else t13.total end as 'Sofa',case when t14.total is null then 0 else t14.total end as 'Flipflop',case when t15.total is null then 0 else t15.total end as 'Ottoman',case when t16.total is null then 0 else t16.total end as 'Cabinet',case when t17.total is null then 0 else t17.total end as 'Shelf',case when t8.total is null then 0 else t8.total end as 'Lamp',case when t1.total is null then 0 else t1.total end as 'Bedroom',case when t1.total_2 is null then 0 else t1.total_2 end as 'Bedroom-Mirror',case when t1.total_3 is null then 0 else t1.total_3 end as 'Bedroom-Dresser',case when t1.total_4 is null then 0 else t1.total_4 end as 'Bedroom-Queen Bed',case when t1.total_5 is null then 0 else t1.total_5 end as 'Bedroom-King bed',case when t1.total_6 is null then 0 else t1.total_6 end as 'Bedroom-Twin  Bed',case when t1.total_7 is null then 0 else t1.total_7 end as 'Bedroom-Full Bed',case when t1.total_8 is null then 0 else t1.total_8 end as 'Bedroom-Cal King Bed',case when t1.total_9 is null then 0 else t1.total_9 end as 'Bedroom-Other',case when t1.total_10 is null then 0 else t1.total_10 end as 'Bedroom-Bench',case when t1.total_11 is null then 0 else t1.total_11 end as 'Bedroom-Chest',case when t1.total_12 is null then 0 else t1.total_12 end as 'Bedroom-Nightstand',case when t1.total_13 is null then 0 else t1.total_13 end as 'Bedroom-Bunk Bed',case when t1.total_14 is null then 0 else t1.total_14 end as 'Bedroom-Day Bed',case when t1.total_15 is null then 0 else t1.total_15 end as 'Bedroom-Vanity',case when t6.total is null then 0 else t6.total end as 'Youth Bedroom',case when t6.total_2 is null then 0 else t6.total_2 end as 'Youth Bedroom-Mirror',case when t6.total_3 is null then 0 else t6.total_3 end as 'Youth Bedroom-Dresser',case when t6.total_4 is null then 0 else t6.total_4 end as 'Youth Bedroom-Queen Bed',case when t6.total_5 is null then 0 else t6.total_5 end as 'Youth Bedroom-King bed',case when t6.total_6 is null then 0 else t6.total_6 end as 'Youth Bedroom-Twin  Bed',case when t6.total_7 is null then 0 else t6.total_7 end as 'Youth Bedroom-Full Bed',case when t6.total_8 is null then 0 else t6.total_8 end as 'Youth Bedroom-Cal King Bed',case when t6.total_9 is null then 0 else t6.total_9 end as 'Youth Bedroom-Other',case when t6.total_10 is null then 0 else t6.total_10 end as 'Youth Bedroom-Bench',case when t6.total_11 is null then 0 else t6.total_11 end as 'Youth Bedroom-Chest',case when t6.total_12 is null then 0 else t6.total_12 end as 'Youth Bedroom-Nightstand',case when t6.total_13 is null then 0 else t6.total_13 end as 'Youth Bedroom-Bunk Bed',case when t6.total_14 is null then 0 else t6.total_14 end as 'Youth Bedroom-Day Bed',case when t6.total_15 is null then 0 else t6.total_15 end as 'Youth Bedroom-Vanity',case when t2.total is null then 0 else t2.total end as 'Dining',case when t2.total_2 is null then 0 else t2.total_2 end as 'Dining-Extension Table',case when t2.total_3 is null then 0 else t2.total_3 end as 'Dining-Standard Height Table',case when t2.total_4 is null then 0 else t2.total_4 end as 'Dining-Pub Table',case when t2.total_5 is null then 0 else t2.total_5 end as 'Dining-Arm Chair',case when t2.total_6 is null then 0 else t2.total_6 end as 'Dining-Side Chair',case when t2.total_7 is null then 0 else t2.total_7 end as 'Dining-Bench',case when t2.total_8 is null then 0 else t2.total_8 end as 'Dining-Hutch',case when t2.total_9 is null then 0 else t2.total_9 end as 'Dining-Buffet',case when t2.total_10 is null then 0 else t2.total_10 end as 'Dining-Server',case when t2.total_11 is null then 0 else t2.total_11 end as 'Dining-Other',case when t2.total_12 is null then 0 else t2.total_12 end as 'Dining-Barstools',case when t2.total_13 is null then 0 else t2.total_13 end as 'Dining-China',case when t2.total_14 is null then 0 else t2.total_14 end as 'Dining-5 in 1',case when t3.total is null then 0 else t3.total end as 'Occasional',case when t3.total_2 is null then 0 else t3.total_2 end as 'Occasional-3-Pack Wood',case when t3.total_3 is null then 0 else t3.total_3 end as 'Occasional-3-Pack Metal',case when t3.total_4 is null then 0 else t3.total_4 end as 'Occasional-Cocktail',case when t3.total_5 is null then 0 else t3.total_5 end as 'Occasional-End Table',case when t3.total_6 is null then 0 else t3.total_6 end as 'Occasional-Chair-Side Table',case when t3.total_7 is null then 0 else t3.total_7 end as 'Occasional-Sofa Table',case when t3.total_8 is null then 0 else t3.total_8 end as 'Occasional-Other',case when t3.total_9 is null then 0 else t3.total_9 end as 'Occasional-Trunk',case when t4.total is null then 0 else t4.total end as 'Home Office',case when t4.total_2 is null then 0 else t4.total_2 end as 'Home Office-Desk',case when t4.total_3 is null then 0 else t4.total_3 end as 'Home Office-File Cabinet',case when t4.total_4 is null then 0 else t4.total_4 end as 'Home Office-Credenza',case when t4.total_5 is null then 0 else t4.total_5 end as 'Home Office-Hutch',case when t4.total_6 is null then 0 else t4.total_6 end as 'Home Office-Bookcase',case when t4.total_7 is null then 0 else t4.total_7 end as 'Home Office-Chair',case when t4.total_8 is null then 0 else t4.total_8 end as 'Home Office-Other',case when t5.total is null then 0 else t5.total end as 'Wall Unit',case when t5.total_2 is null then 0 else t5.total_2 end as 'Wall Unit-TV Stand',case when t5.total_3 is null then 0 else t5.total_3 end as 'Wall Unit-Pier',case when t5.total_4 is null then 0 else t5.total_4 end as 'Wall Unit-Bridge',case when t5.total_5 is null then 0 else t5.total_5 end as 'Wall Unit-Other',case when t7.total is null then 0 else t7.total end as 'Accent',case when t7.total_2 is null then 0 else t7.total_2 end as 'Accent-Throws',case when t7.total_3 is null then 0 else t7.total_3 end as 'Accent-Pouf',case when t7.total_4 is null then 0 else t7.total_4 end as 'Accent-Table Top',case when t7.total_5 is null then 0 else t7.total_5 end as 'Accent-Pillows',case when t7.total_6 is null then 0 else t7.total_6 end as 'Accent-Wall Art',case when t7.total_7 is null then 0 else t7.total_7 end as 'Accent-Top Of Bed',case when t7.total_8 is null then 0 else t7.total_8 end as 'Accent-Other',case when t18.total is null then 0 else t18.total end as 'Upholstery',case when t18.total_2 is null then 0 else t18.total_2 end as 'Upholstery-Sofa',case when t18.total_3 is null then 0 else t18.total_3 end as 'Upholstery-Flip-Flop',case when t18.total_4 is null then 0 else t18.total_4 end as 'Upholstery-Accent Chair',case when t18.total_5 is null then 0 else t18.total_5 end as 'Upholstery-Ottoman',case when t18.total_6 is null then 0 else t18.total_6 end as 'Upholstery-Sectional',case when t18.total_7 is null then 0 else t18.total_7 end as 'Upholstery-Loveseat',case when t18.total_8 is null then 0 else t18.total_8 end as 'Upholstery-Recliner',case when t18.total_9 is null then 0 else t18.total_9 end as 'Upholstery-Other',case when t9.total is null then 0 else t9.total end as 'Accessory',case when t9.total_2 is null then 0 else t9.total_2 end as 'Accessory-Greenery',case when t9.total_3 is null then 0 else t9.total_3 end as 'Accessory-Tray',case when t9.total_4 is null then 0 else t9.total_4 end as 'Accessory-Clock',case when t9.total_5 is null then 0 else t9.total_5 end as 'Accessory-Other',case when t9.total_6 is null then 0 else t9.total_6 end as 'Accessory-Candle',case when t9.total_7 is null then 0 else t9.total_7 end as 'Accessory-Wall Art',case when t9.total_8 is null then 0 else t9.total_8 end as 'Accessory-Floral',case when t9.total_9 is null then 0 else t9.total_9 end as 'Accessory-Rug',case when t9.total_10 is null then 0 else t9.total_10 end as 'Accessory-Pillow',case when t9.total_11 is null then 0 else t9.total_11 end as 'Accessory-TOB',case when t9.total_12 is null then 0 else t9.total_12 end as 'Accessory-Candle Holder',case when t9.total_13 is null then 0 else t9.total_13 end as 'Accessory-Vase',case when t9.total_14 is null then 0 else t9.total_14 end as 'Accessory-Storage',case when t9.total_15 is null then 0 else t9.total_15 end as 'Accessory-Throw',case when t9.total_16 is null then 0 else t9.total_16 end as 'Accessory-Dinnerware',case when t9.total_17 is null then 0 else t9.total_17 end as 'Accessory-Table Top Accessory',case when t9.total_18 is null then 0 else t9.total_18 end as 'Accessory-Placemat',case when t9.total_19 is null then 0 else t9.total_19 end as 'Accessory-Photo Frame',case when t9.total_20 is null then 0 else t9.total_20 end as 'Accessory-Diffuser',case when t9.total_21 is null then 0 else t9.total_21 end as 'Accessory-Mirror',case when t9.total_22 is null then 0 else t9.total_22 end as 'Accessory-5-PK Acc',case when t9.total_23 is null then 0 else t9.total_23 end as 'Accessory-Poufs',case when t9.total_24 is null then 0 else t9.total_24 end as 'Accessory-Pendant',case when t9.total_25 is null then 0 else t9.total_25 end as 'Accessory-Filler',case when t9.total_26 is null then 0 else t9.total_26 end as 'Accessory-Bean Bag',case when t9.total_27 is null then 0 else t9.total_27 end as 'Accessory-Stool' FROM (SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 GROUP BY Month) tLEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='10' GROUP BY Month ) t10 ON t.Month=t10.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='11' GROUP BY Month ) t11 ON t.Month=t11.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='12' GROUP BY Month ) t12 ON t.Month=t12.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='13' GROUP BY Month ) t13 ON t.Month=t13.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='14' GROUP BY Month ) t14 ON t.Month=t14.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='15' GROUP BY Month ) t15 ON t.Month=t15.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='16' GROUP BY Month ) t16 ON t.Month=t16.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='17' GROUP BY Month ) t17 ON t.Month=t17.Month 
LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='8' GROUP BY Month ) t8 ON t.Month=t8.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t1_2.total as total_2,t1_3.total as total_3,t1_4.total as total_4,t1_5.total as total_5,t1_6.total as total_6,t1_7.total as total_7,t1_8.total as total_8,t1_9.total as total_9,t1_10.total as total_10,t1_11.total as total_11,t1_12.total as total_12,t1_13.total as total_13,t1_14.total as total_14,t1_15.total as total_15 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Mirror' GROUP BY Month ) t1_2 ON t0.Month=t1_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Dresser' GROUP BY Month ) t1_3 ON t0.Month=t1_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Queen Bed' GROUP BY Month ) t1_4 ON t0.Month=t1_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='King bed' GROUP BY Month ) t1_5 ON t0.Month=t1_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Twin  Bed' GROUP BY Month ) t1_6 ON t0.Month=t1_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Full Bed' GROUP BY Month ) t1_7 ON t0.Month=t1_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Cal King Bed' GROUP BY Month ) t1_8 ON t0.Month=t1_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Other' GROUP BY Month ) t1_9 ON t0.Month=t1_9.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Bench' GROUP BY Month ) t1_10 ON t0.Month=t1_10.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Chest' GROUP BY Month ) t1_11 ON t0.Month=t1_11.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Nightstand' GROUP BY Month ) t1_12 ON t0.Month=t1_12.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Bunk Bed' GROUP BY Month ) t1_13 ON t0.Month=t1_13.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Day Bed' GROUP BY Month ) t1_14 ON t0.Month=t1_14.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='1' AND sub_product_category='Vanity' GROUP BY Month ) t1_15 ON t0.Month=t1_15.Month ) t1 on t1.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t6_2.total as total_2,t6_3.total as total_3,t6_4.total as total_4,t6_5.total as total_5,t6_6.total as total_6,t6_7.total as total_7,t6_8.total as total_8,t6_9.total as total_9,t6_10.total as total_10,t6_11.total as total_11,t6_12.total as total_12,t6_13.total as total_13,t6_14.total as total_14,t6_15.total as total_15 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Mirror' GROUP BY Month ) t6_2 ON t0.Month=t6_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Dresser' GROUP BY Month ) t6_3 ON t0.Month=t6_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Queen Bed' GROUP BY Month ) t6_4 ON t0.Month=t6_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='King bed' GROUP BY Month ) t6_5 ON t0.Month=t6_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Twin  Bed' GROUP BY Month ) t6_6 ON t0.Month=t6_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Full Bed' GROUP BY Month ) t6_7 ON t0.Month=t6_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Cal King Bed' GROUP BY Month ) t6_8 ON t0.Month=t6_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Other' GROUP BY Month ) t6_9 ON t0.Month=t6_9.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Bench' GROUP BY Month ) t6_10 ON t0.Month=t6_10.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Chest' GROUP BY Month ) t6_11 ON t0.Month=t6_11.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Nightstand' GROUP BY Month ) t6_12 ON t0.Month=t6_12.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Bunk Bed' GROUP BY Month ) t6_13 ON t0.Month=t6_13.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Day Bed' GROUP BY Month ) t6_14 ON t0.Month=t6_14.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='6' AND sub_product_category='Vanity' GROUP BY Month ) t6_15 ON t0.Month=t6_15.Month ) t6 on t6.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t2_2.total as total_2,t2_3.total as total_3,t2_4.total as total_4,t2_5.total as total_5,t2_6.total as total_6,t2_7.total as total_7,t2_8.total as total_8,t2_9.total as total_9,t2_10.total as total_10,t2_11.total as total_11,t2_12.total as total_12,t2_13.total as total_13,t2_14.total as total_14 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Extension Table' GROUP BY Month ) t2_2 ON t0.Month=t2_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Standard Height Table' GROUP BY Month ) t2_3 ON t0.Month=t2_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Pub Table' GROUP BY Month ) t2_4 ON t0.Month=t2_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Arm Chair' GROUP BY Month ) t2_5 ON t0.Month=t2_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Side Chair' GROUP BY Month ) t2_6 ON t0.Month=t2_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Bench' GROUP BY Month ) t2_7 ON t0.Month=t2_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Hutch' GROUP BY Month ) t2_8 ON t0.Month=t2_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Buffet' GROUP BY Month ) t2_9 ON t0.Month=t2_9.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Server' GROUP BY Month ) t2_10 ON t0.Month=t2_10.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Other' GROUP BY Month ) t2_11 ON t0.Month=t2_11.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='Barstools' GROUP BY Month ) t2_12 ON t0.Month=t2_12.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='China' GROUP BY Month ) t2_13 ON t0.Month=t2_13.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='2' AND sub_product_category='5 in 1' GROUP BY Month ) t2_14 ON t0.Month=t2_14.Month ) t2 on t2.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t3_2.total as total_2,t3_3.total as total_3,t3_4.total as total_4,t3_5.total as total_5,t3_6.total as total_6,t3_7.total as total_7,t3_8.total as total_8,t3_9.total as total_9 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='3-Pack Wood' GROUP BY Month ) t3_2 ON t0.Month=t3_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='3-Pack Metal' GROUP BY Month ) t3_3 ON t0.Month=t3_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='Cocktail' GROUP BY Month ) t3_4 ON t0.Month=t3_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='End Table' GROUP BY Month ) t3_5 ON t0.Month=t3_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='Chair-Side Table' GROUP BY Month ) t3_6 ON t0.Month=t3_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='Sofa Table' GROUP BY Month ) t3_7 ON t0.Month=t3_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='Other' GROUP BY Month ) t3_8 ON t0.Month=t3_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='3' AND sub_product_category='Trunk' GROUP BY Month ) t3_9 ON t0.Month=t3_9.Month ) t3 on t3.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t4_2.total as total_2,t4_3.total as total_3,t4_4.total as total_4,t4_5.total as total_5,t4_6.total as total_6,t4_7.total as total_7,t4_8.total as total_8 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Desk' GROUP BY Month ) t4_2 ON t0.Month=t4_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='File Cabinet' GROUP BY Month ) t4_3 ON t0.Month=t4_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Credenza' GROUP BY Month ) t4_4 ON t0.Month=t4_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Hutch' GROUP BY Month ) t4_5 ON t0.Month=t4_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Bookcase' GROUP BY Month ) t4_6 ON t0.Month=t4_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Chair' GROUP BY Month ) t4_7 ON t0.Month=t4_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='4' AND sub_product_category='Other' GROUP BY Month ) t4_8 ON t0.Month=t4_8.Month ) t4 on t4.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t5_2.total as total_2,t5_3.total as total_3,t5_4.total as total_4,t5_5.total as total_5 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='5' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='5' AND sub_product_category='TV Stand' GROUP BY Month ) t5_2 ON t0.Month=t5_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='5' AND sub_product_category='Pier' GROUP BY Month ) t5_3 ON t0.Month=t5_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='5' AND sub_product_category='Bridge' GROUP BY Month ) t5_4 ON t0.Month=t5_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='5' AND sub_product_category='Other' GROUP BY Month ) t5_5 ON t0.Month=t5_5.Month ) t5 on t5.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t7_2.total as total_2,t7_3.total as total_3,t7_4.total as total_4,t7_5.total as total_5,t7_6.total as total_6,t7_7.total as total_7,t7_8.total as total_8 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Throws' GROUP BY Month ) t7_2 ON t0.Month=t7_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Pouf' GROUP BY Month ) t7_3 ON t0.Month=t7_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Table Top' GROUP BY Month ) t7_4 ON t0.Month=t7_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Pillows' GROUP BY Month ) t7_5 ON t0.Month=t7_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Wall Art' GROUP BY Month ) t7_6 ON t0.Month=t7_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Top Of Bed' GROUP BY Month ) t7_7 ON t0.Month=t7_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='7' AND sub_product_category='Other' GROUP BY Month ) t7_8 ON t0.Month=t7_8.Month ) t7 on t7.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t18_2.total as total_2,t18_3.total as total_3,t18_4.total as total_4,t18_5.total as total_5,t18_6.total as total_6,t18_7.total as total_7,t18_8.total as total_8,t18_9.total as total_9 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Sofa' GROUP BY Month ) t18_2 ON t0.Month=t18_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Flip-Flop' GROUP BY Month ) t18_3 ON t0.Month=t18_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Accent Chair' GROUP BY Month ) t18_4 ON t0.Month=t18_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Ottoman' GROUP BY Month ) t18_5 ON t0.Month=t18_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Sectional' GROUP BY Month ) t18_6 ON t0.Month=t18_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Loveseat' GROUP BY Month ) t18_7 ON t0.Month=t18_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Recliner' GROUP BY Month ) t18_8 ON t0.Month=t18_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='18' AND sub_product_category='Other' GROUP BY Month ) t18_9 ON t0.Month=t18_9.Month ) t18 on t18.Month=t.Month 
 LEFT JOIN (  SELECT t0.Month,t0.total,t9_2.total as total_2,t9_3.total as total_3,t9_4.total as total_4,t9_5.total as total_5,t9_6.total as total_6,t9_7.total as total_7,t9_8.total as total_8,t9_9.total as total_9,t9_10.total as total_10,t9_11.total as total_11,t9_12.total as total_12,t9_13.total as total_13,t9_14.total as total_14,t9_15.total as total_15,t9_16.total as total_16,t9_17.total as total_17,t9_18.total as total_18,t9_19.total as total_19,t9_20.total as total_20,t9_21.total as total_21,t9_22.total as total_22,t9_23.total as total_23,t9_24.total as total_24,t9_25.total as total_25,t9_26.total as total_26,t9_27.total as total_27 FROM  ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' GROUP BY Month ) t0  LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Greenery' GROUP BY Month ) t9_2 ON t0.Month=t9_2.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Tray' GROUP BY Month ) t9_3 ON t0.Month=t9_3.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Clock' GROUP BY Month ) t9_4 ON t0.Month=t9_4.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Other' GROUP BY Month ) t9_5 ON t0.Month=t9_5.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Candle' GROUP BY Month ) t9_6 ON t0.Month=t9_6.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Wall Art' GROUP BY Month ) t9_7 ON t0.Month=t9_7.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Floral' GROUP BY Month ) t9_8 ON t0.Month=t9_8.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Rug' GROUP BY Month ) t9_9 ON t0.Month=t9_9.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Pillow' GROUP BY Month ) t9_10 ON t0.Month=t9_10.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='TOB' GROUP BY Month ) t9_11 ON t0.Month=t9_11.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Candle Holder' GROUP BY Month ) t9_12 ON t0.Month=t9_12.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Vase' GROUP BY Month ) t9_13 ON t0.Month=t9_13.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Storage' GROUP BY Month ) t9_14 ON t0.Month=t9_14.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Throw' GROUP BY Month ) t9_15 ON t0.Month=t9_15.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Dinnerware' GROUP BY Month ) t9_16 ON t0.Month=t9_16.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Table Top Accessory' GROUP BY Month ) t9_17 ON t0.Month=t9_17.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Placemat' GROUP BY Month ) t9_18 ON t0.Month=t9_18.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Photo Frame' GROUP BY Month ) t9_19 ON t0.Month=t9_19.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Diffuser' GROUP BY Month ) t9_20 ON t0.Month=t9_20.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Mirror' GROUP BY Month ) t9_21 ON t0.Month=t9_21.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='5-PK Acc' GROUP BY Month ) t9_22 ON t0.Month=t9_22.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Poufs' GROUP BY Month ) t9_23 ON t0.Month=t9_23.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Pendant' GROUP BY Month ) t9_24 ON t0.Month=t9_24.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Filler' GROUP BY Month ) t9_25 ON t0.Month=t9_25.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Bean Bag' GROUP BY Month ) t9_26 ON t0.Month=t9_26.Month LEFT JOIN ( SELECT FROM_UNIXTIME(create_time,'%Y%m') AS Month,count(*) AS total from mf_product_intelligence WHERE `status`=1 AND product_category='9' AND sub_product_category='Stool' GROUP BY Month ) t9_27 ON t0.Month=t9_27.Month ) t9 on t9.Month=t.Month;