Select
Total_Jam,Dumpers_jam,Inbound_jam,Runout_jam,Sorter_Recirc_jam,Startstamp,Endtstamp,Sorter_jam,

1 as Total_perc,
Dumpers_jam/Total_Jam as Dumpers_perc,
Inbound_jam/Total_Jam as Inbound_perc,
Runout_jam/Total_Jam as Runout_perc,
Sorter_Recirc_jam/Total_Jam as Sorter_Recirc_perc,
Sorter_jam/Total_Jam as Sorter_perc


FROM

		(SELECT 
		  
		  MIN(jam_area.t_stamp) AS Startstamp, 
	   	  Max(jam_area.t_stamp) AS Endtstamp,
	   	  SUM (IFNULL(`jam_ulgl`,0) + IFNULL(`Inbound_jam`, 0)+ IFNULL(`Runout_jam`, 0) + IFNULL(`Sorter_recirc`,0)+ IFNULL(`Sorter_jam`,0)) AS Total_Jam,	   
		  SUM(jam_area.jam_ulgl = 1) AS Dumpers_jam,
		  SUM(jam_area.Inbound_jam = 1) AS Inbound_jam,
		  SUM(jam_area.Runout_jam = 1) AS Runout_jam,
		  SUM(jam_area.Sorter_recirc = 1) AS Sorter_Recirc_jam,
		  SUM(jam_area.Sorter_jam = 1) AS Sorter_jam
		  
		FROM jam_area
		Where (jam_area.t_stamp BETWEEN :starttime AND :endtime)) basajam