Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help needed with SQL query

Author  Topic 

htdarey78
Starting Member

1 Post

Posted - 2009-03-10 : 14:35:03
Hi I'm trying to set up a query. I'm working on teaching myself SQL and can't seem to get it. Below is the query and my tables.

Show, for each date, the date and the number of orders placed on that date. Sort the output by the date.

CUSTOMER, which contains information (customer ID, name, address, city, state, and zip) for customers of the company;

PRODUCT, which contains information (product ID, description, finish, and price) for products sold by the company;

ORDERTABLE, which contains information (order ID, order date, and customer ID) for orders placed with the company;

ORDERLINE, which contains information (order ID, product ID, and quantity) for individual products requested in orders.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-10 : 14:38:07
[code]
SELECT DATEADD(dd,DATEDIFF(dd,0,orderdate),0),COUNT(orderID) AS OrderCount
FROM ORDERTABLE
GROUP BY DATEADD(dd,DATEDIFF(dd,0,orderdate),0)
ORDER BY DATEADD(dd,DATEDIFF(dd,0,orderdate),0)
[/code]

if you want to list dates with no orders as well you need to use a count table.
Go to Top of Page
   

- Advertisement -