abrahamgarcia27 Posted November 15, 2013 Share Posted November 15, 2013 I can't seem to figure out how to structure the following query. I have two type of content 1= helmet 2 = shoulder pads and i have grouped it by school_barcode it gives me all the rows in one result which is what i want. But now i want it to SUM all the count where the type is 1 and type is 2 and give me two different results. I have this table detail_id school_barcode bag_number type_content count receiving_id freight_bill time_stamp and have the following query $sql = "SELECT SUM(count), `".TABLE_RECEIVING_DETAIL."`.school_barcode, `".TABLE_SCHOOL."`.name FROM `".TABLE_RECEIVING_DETAIL."` LEFT JOIN `".TABLE_SCHOOL."` on `".TABLE_RECEIVING_DETAIL."`.school_barcode = `".TABLE_SCHOOL."`.bar_code WHERE receiving_id = '$receiving_id' AND freight_bill = '$freight_bill' GROUP BY school_barcode"; The end result should be Customer # | Cutomer Name | Helmets Received SUM | Shoulder Pads Received SUM Quote Link to comment https://forums.phpfreaks.com/topic/283900-query-help/ Share on other sites More sharing options...
Barand Posted November 15, 2013 Share Posted November 15, 2013 GROUP BY school_barcode, type_content Quote Link to comment https://forums.phpfreaks.com/topic/283900-query-help/#findComment-1458349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.