SELECT CONCAT('Hour : ',HOUR(`TimeStamp`)) as Hour, SUM(Total) as Amount, Count(Voucher_No) as Count  FROM $trans_db.Sales_Invoice_Main Where Voucher_No in (SELECT Voucher_No from $trans_db.Sales_Invoice_Main stable  WHERE str_to_Date(concat(stable.Voucher_Date, substr(`TimeStamp`, 11,19)) ,'%Y-%m-%d %H:%i:%s') >=str_to_date('$fromDateTime','%Y-%m-%d %H:%i:%s') and str_to_Date(concat(stable.Voucher_Date, substr(`TimeStamp`, 11,19)) ,'%Y-%m-%d %H:%i:%s') <=str_to_date('$toDateTime','%Y-%m-%d %H:%i:%s')) GROUP BY HOUR(`TimeStamp`) ORDER BY HOUR(`TimeStamp`)