Subject | Re: Select statement column lists question - Invalid Token |
---|---|
Author | Peter Welch |
Post date | 2008-03-02T17:34:15Z |
Svein,
Thank you for your quick reply (and sorry for my late one). Yes, the
following works:
select count(*)
, cast(o.aDT as date)
, p.category
from orders o, procs p
where p.proc_id = o.proc_id
group by 2, 3
order by 1;
Actually, as I investigate all the issues, it seems I will be best
served by creating a mini-datawarehouse, since the long term usage
will involve several dimensions. Originally, I was hoping to do a
simple "table lookup" for each column of IDs but, in the end, that
means a join for each.
If you ever think of the way to accomplish my original Sql effort as
you thought might be possible, I'd be glad to see it.
Thanks again,
Pete
--- In firebird-support@yahoogroups.com, Svein Erling Tysvaer
<svein.erling.tysvaer@...> wrote:
Thank you for your quick reply (and sorry for my late one). Yes, the
following works:
select count(*)
, cast(o.aDT as date)
, p.category
from orders o, procs p
where p.proc_id = o.proc_id
group by 2, 3
order by 1;
Actually, as I investigate all the issues, it seems I will be best
served by creating a mini-datawarehouse, since the long term usage
will involve several dimensions. Originally, I was hoping to do a
simple "table lookup" for each column of IDs but, in the end, that
means a join for each.
If you ever think of the way to accomplish my original Sql effort as
you thought might be possible, I'd be glad to see it.
Thanks again,
Pete
--- In firebird-support@yahoogroups.com, Svein Erling Tysvaer
<svein.erling.tysvaer@...> wrote:
>orders.proc_id )
> Hi, Peter!
>
> With Firebird 2.1 (I don't know about Firebird 2.0), you can do
>
> select count(*), cast(dt.aDT as date), dt.category
> from
> (select o.*
> ,(select p.category from procedures p where proc_id =
> as categorythis
> from orders o) dt
> group by 2, 3
> order by 1;
>
> All versions of Firebird should be able to handle something like
> using a VIEW, and - of course - the obvious LEFT JOIN that I simplyare
> forgot and that should work almost regardless of which version you
> using (this would be my preferred way to do what you're trying todo):
>ago
> select count(*)
> , cast(o.aDT as date)
> , p.category
> from orders o
> left join procedures p on p.proc_id = o.proc_id
> group by 2, 3
> order by 1;
>
> I think your original select may work as well if you do something
> clever. At least I think I had a slightly similar situation a while
> that got solved on this list using an additional field in the groupby
> (I remember it surprised me when I saw the solution, but I don'tquite
> remember what was my problem, nor what the solution was).orders.proc_id )
>
> HTH,
> Set
>
> Peter Welch wrote:
> > I want to do a fairly simple 'group by' select statement but only
> > certain combinations work.
> >
> > What I want is the following to work:
> >
> > select count(*)
> > , cast(aDT as date)
> > ,(select category from procedures where proc_id =
> > from ordersor
> > group by 1,2
> > order by 1;
> >
> > Running the above causes the ambiguous Invalid Token error (with
> > without the count(*) column).orders.proc_id )
> >
> > I can do the following:
> >
> > select
> > cast(aDT as date)
> > ,(select category from procedures where proc_id =
> > from ordersdon't
> > order by 1;
> >
> > but no 'group by' or count(*)
> >
> > Or, I can do the following:
> >
> > select count(*)
> > , cast(aDT as date)
> > from orders
> > group by 2
> > order by 1;
> >
> > But no '(select category from ....'
> >
> > I would prefer not to turn this into a stored procedure, but
> > see any other way.
> >
> > Any suggestions greatly appreciated,
> >
> > Pete
>