Subject | Re: [firebird-support] having max() doesn't work in Firebird |
---|---|
Author | Nando Dessena |
Post date | 2004-06-01T19:52:25Z |
Bill,
B> The error indicates that Max() can no longer be used in the having clause.
not really. See below.
B> select b.CntId, Prd.Dsc, max(a.EffDt)
B> from Cnt a, Cnt b, Prd, SchCtl
B> where a.CntEntId = b.CntEntId
B> and a.PrdId = b.PrdId
B> and b.PrdId = Prd.PrdId
B> and a.CntEntId = 2
B> and Prd.PyrId = 8
B> and a.CntId = SchCtl.CntId
B> group by b.CntId, Prd.Dsc
B> having b.EffDt = max(a.EffDt) <--- gives error message below
B> order by Prd.Dsc
B> Error message: Invalid expression in the HAVING clause (neither an aggregate
B> function nor a part of the GROUP BY clause)
B> I set the group by to look like this:
B> group by b.CntId, Prd.Dsc, max(a.EffDt
B> and that didn't work either.
B> Any suggestions?
Yes. This query doesn't make sense and you should thank Firebird for
telling you. :-) The problem is that you can only include in the HAVING
clause columns that are also parte of the GROUP BY clause or aggregate
functions. b.EffDt doesn't satisfy the requirement.
I haven't got a clue what kind of result you expect, but I hope this
information will be useful to fix your query.
Ciao
--
Nando Dessena
mailto:nandod@...
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================
B> The error indicates that Max() can no longer be used in the having clause.
not really. See below.
B> select b.CntId, Prd.Dsc, max(a.EffDt)
B> from Cnt a, Cnt b, Prd, SchCtl
B> where a.CntEntId = b.CntEntId
B> and a.PrdId = b.PrdId
B> and b.PrdId = Prd.PrdId
B> and a.CntEntId = 2
B> and Prd.PyrId = 8
B> and a.CntId = SchCtl.CntId
B> group by b.CntId, Prd.Dsc
B> having b.EffDt = max(a.EffDt) <--- gives error message below
B> order by Prd.Dsc
B> Error message: Invalid expression in the HAVING clause (neither an aggregate
B> function nor a part of the GROUP BY clause)
B> I set the group by to look like this:
B> group by b.CntId, Prd.Dsc, max(a.EffDt
B> and that didn't work either.
B> Any suggestions?
Yes. This query doesn't make sense and you should thank Firebird for
telling you. :-) The problem is that you can only include in the HAVING
clause columns that are also parte of the GROUP BY clause or aggregate
functions. b.EffDt doesn't satisfy the requirement.
I haven't got a clue what kind of result you expect, but I hope this
information will be useful to fix your query.
Ciao
--
Nando Dessena
mailto:nandod@...
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================