This topic is locked

Select year and month of a sale

4/6/2012 9:59:23 AM
PHPRunner General questions
J
joiresende author

Hello, I need a way to be able to select the month in the following SQL query.

SELECT

MONTHNAME (SaleDate) AS Month,

COUNT (*) AS sales,

Employee,

SaleDate,

sales AS sales1

FROM sales

GROUP BY Employee

ORDER BY level DESC

if I add the line "WHERE (month (SaleDate) = month (now ()))" I can see the sale of the current month and for example I add the line "WHERE (MONTH (SaleDate) = 12)" I can see sales for the month of December.

What I need is a way for the user to select the year and month of sales.

S
stiven 4/6/2012



Hello, I need a way to be able to select the month in the following SQL query.

SELECT

MONTHNAME (SaleDate) AS Month,

COUNT (*) AS sales,

Employee,

SaleDate,

sales AS sales1

FROM sales

GROUP BY Employee

ORDER BY level DESC

if I add the line "WHERE (month (SaleDate) = month (now ()))" I can see the sale of the current month and for example I add the line "WHERE (MONTH (SaleDate) = 12)" I can see sales for the month of December.

What I need is a way for the user to select the year and month of sales.


how about if you try "WHERE (MONTH (SaleDate) = 12 AND YEAR (SaleDate) = 2012)"??

J
joiresende author 4/7/2012

Dear Stivens, sorry for my english, I reversed the question for a better understanding
I have a simple control of sales and need to know what each salesperson sells monthly and year. Or need to select the year after the month of sales.
I have the following SQL query.

SELECT

MONTHNAME (SaleDate) AS Month,

COUNT (*) AS sales,

Employee,

SaleDate,

Sales AS VendaMensal

FROM sales

GROUP BY Employee

ORDER BY level DESC

If I use desda way I see all the sales of every month ..

If I acrecento the line "WHERE (MONTH (SaleDate) = 12)" I see the month's sales in December without specifying the year.

If I change this line as "WHERE (year (SaleDate) = 2012) I see all sales in the year 2012.

If I change the above lines as "WHERE (month (SaleDate) = month (now ()))" I see the date of the current month without specifying the year.
What I'm needing is a way, that when the user opens the page has the current month and year and he has the option to choose the year and month of sales.

J
joiresende author 4/7/2012

It did not work