This topic is locked
[SOLVED]

 month to month sql query

12/31/2011 5:52:58 AM
PHPRunner General questions
J
joiresende author

Good morning everyone.

I have a table

Date_Sale

Cod_sale

product

need to do a sql query to count how many particular product sold in the month. For example the months of May sold 10 knives in the month of December 6 sold knives.

I can make a query to count how many products have been sold but can not separate month to month.

Sorry for my english

C
cgphp 12/31/2011
$sql = "SELECT COUNT(*) as num_products FROM table_name WHERE MONTH(Date_Sale) = 5 AND product='knifes'";



5 means May
If you want to get the count for each month in only one query:

$sql = "SELECT MONTH(Date_Sale) as months, COUNT(*) as num_products FROM table_name WHERE product='knifes' GROUP BY MONTH(Date_Sale)";
J
joiresende author 12/31/2011


$sql = "SELECT COUNT(*) as num_products FROM table_name WHERE MONTH(Date_Sale) = 5 AND product='knifes'";



5 means May
If you want to get the count for each month in only one query:

$sql = "SELECT MONTH(Date_Sale) as months, COUNT(*) as num_products FROM table_name WHERE product='knifes' GROUP BY MONTH(Date_Sale)";




thanks for the quick response.

I understand but do not know Where do I put this code.

and how do I select more than one product, such as knives, forks, spoons, sold for months

C
cgphp 12/31/2011

I can't tell you where to put the code if I don't know much more about what you want to achieve.

J
joiresende author 12/31/2011

Cristian, thanks for the help

What is wanted is to say sql query or property of the page view. And how can I see more than one product

C
cgphp 12/31/2011

Not sure I understand what you mean. Could you post some screenshot to better illustrate your request?

J
joiresende author 1/1/2012

thanks for the help, I managed to solve.