Forum Moderators: open

Message Too Old, No Replies

MSSQL+Date

         

stevelibby

10:18 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Hello
I am doing a query but am stuck.
I want to customers but group them by date. Query as follows:
SELECT Count(Customers.CustomersID) AS CountOfCustomersID, Customers.Date
FROM Customers
GROUP BY Customers.Date;
The date field in mysql is a date(), My question is how can i get them to show by month? they currently show by day.

aspdaddy

11:31 am on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SQL has a month function that returns a number

SELECT Count(Customers.CustomersID) AS CountOfCustomersID, Month(Customers.Date)
FROM Customers
GROUP BY Month(Customers.Date)

syber

11:49 am on Apr 28, 2005 (gmt 0)

10+ Year Member



If you want to group by calendar month, I would suggest:

SELECT Count(Customers.CustomersID) AS CountOfCustomersID, Year(Customers.Date), Month(Customers.Date)
FROM Customers
GROUP BY Year(Customers.Date), Month(Customers.Date)
ORDER BY Year(Customers.Date), Month(Customers.Date)

Art

stevelibby

11:55 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Hi
I have just tried and it doesnt work? what am i doing wrong?

mattglet

12:37 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are you getting for an error?

Easy_Coder

12:45 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried the DatePart function

SELECT DATEPART(month, GETDATE()) AS 'Month Number'

stevelibby

1:42 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



i have run both code in frontpage wizard, which is how i do all queries, but once uploaded doesnt give anything anther than unable to show results.

aspdaddy

4:10 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the title you put MSSQL & in the message MySQL-which database are you using?