Help - SQL Statements

  • Thread starter Thread starter A P
  • Start date Start date
A

A P

Hi,

Can you help me with SQL Statements? Currently, I am practicing SQL
statements using Northwind Database from MS SQL, hope you can answer my
question:

1. How many times were the products with ProductID 1 to 5 ordered in 1997?
2. How many of each product whose ProductID is from 10 to 15 have been
ordered by all customers?
3. How many orders were placed by each customer per year?

Your answer will really help me understand SQL. Please make the statement as
simple as it is so I can easily understand.

thanks,

Me
 
Here ya go:

-- Problem 1
select
count (*)
from
Orders o
join [Order Details] od on od.OrderID = o.OrderID
where
o.OrderDate >= '19970101'
and o.OrderDate < '19980101'
and od.ProductID between 1 and 5

-- Problem 2
select
sum (Quantity)
from
[Order Details]
where
ProductID between 10 and 15

-- Problem 3
select
CustomerID
, year (OrderDate)
, count (*)
from
Orders
group by
CustomerID
, year (OrderDate)
order by
CustomerID
, year (OrderDate)


--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
Hi,

Can you help me with SQL Statements? Currently, I am practicing SQL
statements using Northwind Database from MS SQL, hope you can answer my
question:

1. How many times were the products with ProductID 1 to 5 ordered in 1997?
2. How many of each product whose ProductID is from 10 to 15 have been
ordered by all customers?
3. How many orders were placed by each customer per year?

Your answer will really help me understand SQL. Please make the statement as
simple as it is so I can easily understand.

thanks,

Me
 
I'm usually in here every day, but I've just been away on vacation for 2
weeks.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
thanks tom, I needed that. Hope to hear from you on the near future?
 
Back
Top