sql+=" AND (dp.end_total_count > dp.base_total_count) GROUP BY dp.machine_id, dp.program_name, m.name HAVING SUM(dp.end_total_count - dp.base_total_count) > 0 ORDER BY TotalQuantity DESC";
stringsql=@"SELECT w.name AS WorkerName, COUNT(DISTINCT wm.machine_id) AS MachineCount, COUNT(DISTINCT dp.program_name) AS ProgramCount, COALESCE(SUM(dp.end_total_count - dp.base_total_count), 0) AS TotalQuantity FROM cnc_worker w JOIN cnc_worker_machine wm ON wm.worker_id = w.id LEFT JOIN cnc_daily_production dp ON dp.machine_id = wm.machine_id AND dp.production_date BETWEEN @Start AND @End AND dp.end_total_count > dp.base_total_count";
stringsql=@"SELECT w.name AS WorkerName, COUNT(DISTINCT wm.machine_id) AS MachineCount, COUNT(DISTINCT dp.program_name) AS ProgramCount, COALESCE(SUM(dp.end_total_count - dp.base_total_count), 0) AS TotalQuantity, GROUP_CONCAT(DISTINCT wm.machine_id) AS MachineIds, GROUP_CONCAT(DISTINCT dp.program_name) AS ProgramNames FROM cnc_worker w JOIN cnc_worker_machine wm ON wm.worker_id = w.id LEFT JOIN cnc_daily_production dp ON dp.machine_id = wm.machine_id AND dp.production_date BETWEEN @Start AND @End AND dp.end_total_count > dp.base_total_count";
stringsql=@"SELECT dp.program_name AS ProgramName, COUNT(DISTINCT dp.machine_id) AS MachineCount, SUM(dp.end_total_count - dp.base_total_count) AS TotalQuantity FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.machine_id = m.id WHERE dp.production_date BETWEEN @Start AND @End";
stringsql=@"SELECT dp.program_name AS ProgramName, GROUP_CONCAT(DISTINCT dp.machine_id) AS MachineIds, COUNT(DISTINCT dp.machine_id) AS MachineCount, SUM(dp.end_total_count - dp.base_total_count) AS TotalQuantity FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.machine_id = m.id WHERE dp.production_date BETWEEN @Start AND @End";
sql+=" AND (dp.end_total_count > dp.base_total_count) GROUP BY dp.program_name HAVING SUM(dp.end_total_count - dp.base_total_count) > 0 ORDER BY TotalQuantity DESC";