Jump to content

Recommended Posts

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 

Link to comment
https://forums.phpfreaks.com/topic/283900-query-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.