Subject Re: Crosstab
Author Adam
Getting back to the original question, unedited.

--- In firebird-support@yahoogroups.com, "ra8009" <ra8009@...> wrote:
>
> I have a table with a date and a category. I want to query a count of
> the date occurences by category. Is there an easy way to do this?
>

If the description is correct, then no hoops exist to jump through. He
has a table something like below:

SomeTable
---------

SomeDate SomeCategory

1/1/2006 1
1/1/2006 1
1/1/2006 2
1/1/2006 3
2/1/2006 1
2/1/2006 1

A simple group by will work with this.

Select SomeDate, count(SomeCategory)
from Sometable
group by SomeDate

If the description is wrong however, and it is infact a timestamp
field rather than a date.

SomeTable
---------

SomeTimestamp SomeCategory

1/1/2006 09:00 1
1/1/2006 09:02 1
1/1/2006 09:00 2
1/1/2006 09:00 3
2/1/2006 09:00 1
2/1/2006 09:00 1

Then Richard's suggestion is by far the easiest (ie, casting the
Timestamp to a date)

Select Cast(SomeTimestamp as Date) as SomeDate, count(SomeCategory)
from Sometable
group by 1

This would treat each Timestamp occuring on the same date as identical
for the purpose of the grouping. The method suggested by Jason would
work but it is a lot more tricky then it needs to be.

Any SQL-101 tutorial would show something similar, and unless the
description is lacking, it appears to me to be a group by query with
no complexity to it.

Adam