Select
	SorterName,Induct_count,Sorted_count,OperRecirc_count,MachineRecirc_count,AWCSRecirc_count,Startstamp,Endtstamp,
	Induct_count/Induct_count as Induct_perc,
    Sorted_count/Induct_count as Sorted_perc,
    OperRecirc_count/Induct_count as OperRecirc_perc,
    MachineRecirc_count/Induct_count as MachineRecirc_perc,
    AWCSRecirc_count/Induct_count as AWCSRecirc_perc,
    concat(cast(Induct_count as char),' pph') as Induct_rate,
	concat(cast(Sorted_count as char),' pph') as Sorted_rate,
	concat(cast(OperRecirc_count as char),' pph') as OperRecirc_rate,
	concat(cast(MachineRecirc_count as char),' pph') as MachineRecirc_rate,
	concat(cast(AWCSRecirc_count as char),' pph') as AWCSRecirc_rate	
FROM
	(SELECT 
		  'S01' as SorterName,
		  COUNT(*) AS Induct_count,
		  SUM(alltable.ACTUAL_DEST NOT IN ('S013001', 'S012069', 'S011076')) AS Sorted_count,
 		  SUM(alltable.ACTUAL_DEST IN ('S013001', 'S012069', 'S011076') AND (alltable.DivertStatus & (4|32|262144|524288|1048576)) > 0) AS OperRecirc_count,
		  SUM(alltable.ACTUAL_DEST IN ('S013001', 'S012069', 'S011076') AND (alltable.DivertStatus & (2|8|16|64|8192|16384|131072|2097152)) > 0) AS MachineRecirc_count,
 		  SUM(alltable.ACTUAL_DEST IN ('S013001', 'S012069', 'S011076') AND (alltable.DivertStatus & (128|256|512|1024|4096|65536)) > 0) AS AWCSRecirc_count,
		  MIN(alltable.t_stamp) AS Startstamp, 
		  Max(alltable.t_stamp) AS Endtstamp
FROM alltable
		Where (alltable.t_stamp BETWEEN :starttime AND :endtime)
		Group BY 'S01') basa