> >> >> But when I try to further filter the data with a having clause all I get is
> >> >> a syntax error
> >> >> select ord_id, count(unique ship_num)
> >> >> from ord_l
> >> >> where ord_id < 1000
> >> >> group by ord_id
> >> >> having count(unique ship_num) > 1
> >> Hi!
> >> As far as I remember, using "count(<any_column_you_want>)" is useless by default,
> >> since the number of rows is the same, regardless of the column you count them on.
> >> Simply replace with "count(*)", both in SELECT and HAVING.
> >No, the point failed to make contact with you Dude.
> >count(*) will give you the total rows in each group of ord_id. count(unique ship_num) will give you the number of different ship_num's in each group of ord_id.
> >A very different result.
> Ok, sweetheart, I missed the objective; my BDay today and started with the bear
> a little early.
I've never been arrested for it Dude!Quote:> I might miss it again, but asking never hurts. So: isn't UNIQUE
> inside the COUNT illegal?
Not really. Here are the options:Quote:> I mean, the query translates to something like: "determine
> the groups by ord_id, then determine the sub-groups by ship_num, then count, then filter"
select ord_id, count(*)
which groups by ord_id then counts the number of rows in each group.
select ord_id, count(ship_num)
which groups by ord_id then counts the number of ship_num's in each group. So this is the same as count(*).
select ord_id, count(unique ship_num)
which groups by ord_id then counts the number of unique ship_num's in each group. So if you have two of the same ship_num's in the same group, it will only get counted once.
Try these selects in any database:
select colno, count(*)
from syscolumns
group by 1
order by 1
;
select colno, count(collength)
from syscolumns
group by 1
order by 1
;
select colno, count(unique collength)
from syscolumns
group by 1
order by 1
Have another beer Dude, you have exhausted my brain cell now. Happy BDay!Quote:> So probably a sub-query or "group by ord_id, ship_num" should do the trick.
AB
----------------------------------------------------------------
Get your free email from AltaVista at http://altavista.iname.com