Select COUNT(*) AS Count From (Select D_Goods.GoodsCompanyNo, D_Goods.GoodsNo, D_Goods.GoodsCode From D_Goods Inner Join D_Company ON D_Goods.GoodsCompanyNo = D_Company.CompanyNo Left Join M_LargeClass AS Large1 ON D_Goods.GoodsLargeClassNo1 = Large1.LargeClassNo Left Join M_MediumClass AS Medium1 ON D_Goods.GoodsLargeClassNo1 = Medium1.MediumClassLargeClassNo AND D_Goods.GoodsMediumClassNo1 = Medium1.MediumClassNo Left Join M_SmallClass AS Small1 ON D_Goods.GoodsLargeClassNo1 = Small1.SmallClassLargeClassNo AND D_Goods.GoodsMediumClassNo1 = Small1.SmallClassMediumClassNo AND D_Goods.GoodsSmallClassNo1 = Small1.SmallClassNo Left Join M_LargeClass AS Large2 ON D_Goods.GoodsLargeClassNo2 = Large2.LargeClassNo Left Join M_MediumClass AS Medium2 ON D_Goods.GoodsLargeClassNo2 = Medium2.MediumClassLargeClassNo AND D_Goods.GoodsMediumClassNo2 = Medium2.MediumClassNo Left Join M_SmallClass AS Small2 ON D_Goods.GoodsLargeClassNo2 = Small2.SmallClassLargeClassNo AND D_Goods.GoodsMediumClassNo2 = Small2.SmallClassMediumClassNo AND D_Goods.GoodsSmallClassNo2 = Small2.SmallClassNo Left Join M_LargeClass AS Large3 ON D_Goods.GoodsLargeClassNo3 = Large3.LargeClassNo Left Join M_MediumClass AS Medium3 ON D_Goods.GoodsLargeClassNo3 = Medium3.MediumClassLargeClassNo AND D_Goods.GoodsMediumClassNo3 = Medium3.MediumClassNo Left Join M_SmallClass AS Small3 ON D_Goods.GoodsLargeClassNo3 = Small3.SmallClassLargeClassNo AND D_Goods.GoodsMediumClassNo3 = Small3.SmallClassMediumClassNo AND D_Goods.GoodsSmallClassNo3 = Small3.SmallClassNo Inner Join M_ServiceItem ON D_Goods.GoodsServiceKindNo = M_ServiceItem.ServiceItemServiceKindNo AND D_Goods.GoodsServiceItemNo = M_ServiceItem.ServiceItemNo Inner Join M_Style ON D_Goods.GoodsStyleNo = M_Style.StyleNo Left Join ( Select GoodsQAPCompanyNo, GoodsQAPGoodsNo, COUNT(*) AS QAPCnt From D_GoodsQAP Group By GoodsQAPCompanyNo, GoodsQAPGoodsNo) D_GoodsQAP ON D_Goods.GoodsCompanyNo = GoodsQAPCompanyNo AND D_Goods.GoodsNo = GoodsQAPGoodsNo Where Group By D_Goods.GoodsCompanyNo, D_Goods.GoodsNo, D_Goods.GoodsCode HAVING COUNT(*) >= 0) AS Count
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group By D_Goods.GoodsCompanyNo, D_Goods.GoodsNo, ' at line 32