如下图所示,是我大概想要实现的目标,但是这样写是不对的。当time4 或者 time3 等于 空时,直接不要该查询${if(len(time4) == 0,"","SELECT SUM(IFNULL(number,0)) AS 数量, SUM(IFNULL(amount,0)) AS 金额, \"'" +time4 + " 23:59:59'\" AS 时间FROM ( SELECT * FROM business_engineering_insert WHERE dateTime =LEFT(\"'" +time4 + " 23:59:59'\",10) AND type = 0 ) a RIGHT JOIN ( SELECT id, NAME FROM fine_department WHERE id > 22 AND id < 44 ) b ON a.tableDep = LEFT ( b.`name`, 2 ) GROUP BY dateTime ")} UNION${if(len(time3) == 0,"","SELECT SUM(IFNULL(number,0)) AS 数量, SUM(IFNULL(amount,0)) AS 金额, \"'" +time3 + " 23:59:59'\" AS 时间FROM ( SELECT * FROM business_engineering_insert WHERE dateTime =LEFT(\"'" +time3 + " 23:59:59'\",10) AND type = 0 ) a RIGHT JOIN ( SELECT id, NAME FROM fine_department WHERE id > 22 AND id < 44 ) b ON a.tableDep = LEFT ( b.`name`, 2 ) GROUP BY dateTime ")}