how to use count in a query

G

Guest

I cant figure out how to get Count working. I want to know how many orders
somebody made between a range of dates. I used count in one query:
select count(order_id), order_by from orderTable. I am interested in
'order_by', but used order_id as a counter. I get something like this as a
result:
Order_id Order_by
120 Smith
399 Ortel
230 Bert
Now, what I would like to do is to get the same information, but add a date
range to this . For example, I'd like to see how many times Ortel ordered
something between Jan 06 through Dec 06. I copied my first query and pasted
it, and tried to add totals to it , plus date ranges. When I add the date
range ,my counts are too high. They look like this:
Order_id Order_by Low Range High Range
490 Ortel 1/1/2006 10/1/2006

How in the world do I accomplish this? I am really stuck.
THanks
 
M

Marshall Barton

trevi said:
I cant figure out how to get Count working. I want to know how many orders
somebody made between a range of dates. I used count in one query:
select count(order_id), order_by from orderTable. I am interested in
'order_by', but used order_id as a counter. I get something like this as a
result:
Order_id Order_by
120 Smith
399 Ortel
230 Bert
Now, what I would like to do is to get the same information, but add a date
range to this . For example, I'd like to see how many times Ortel ordered
something between Jan 06 through Dec 06. I copied my first query and pasted
it, and tried to add totals to it , plus date ranges. When I add the date
range ,my counts are too high. They look like this:
Order_id Order_by Low Range High Range
490 Ortel 1/1/2006 10/1/2006


Without seeing your query, it's hard to tell what might be
wrong with it.

The general idea for a totals type query is:

SELECT Order_id, Order_by, Count(*) As OrderCount
FROM table
WHERE OrderDate Between [Start date] And [End date]
GROUP BY Order_id, Order_by
 
G

Guest

Marshall Barton said:
trevi said:
I cant figure out how to get Count working. I want to know how many orders
somebody made between a range of dates. I used count in one query:
select count(order_id), order_by from orderTable. I am interested in
'order_by', but used order_id as a counter. I get something like this as a
result:
Order_id Order_by
120 Smith
399 Ortel
230 Bert
Now, what I would like to do is to get the same information, but add a date
range to this . For example, I'd like to see how many times Ortel ordered
something between Jan 06 through Dec 06. I copied my first query and pasted
it, and tried to add totals to it , plus date ranges. When I add the date
range ,my counts are too high. They look like this:
Order_id Order_by Low Range High Range
490 Ortel 1/1/2006 10/1/2006


Without seeing your query, it's hard to tell what might be
wrong with it.

The general idea for a totals type query is:

SELECT Order_id, Order_by, Count(*) As OrderCount
FROM table
WHERE OrderDate Between [Start date] And [End date]
GROUP BY Order_id, Order_by
Thanks Marsh, I used a "where" for my date range and my counts came out ok.
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top