Subject Re: [firebird-support] Creating a view using COUNT
Author Svein Erling Tysvaer
When using aggregate functions, you have to tell Firebird which fields
it has to group by, in your case

create view VIEW_COMMITMENTS_LEFT ( ID_MEMBER, ID_DONATION,
TOTAL_MONTHS_PAID, MONTHS_COMMITED )
as
select
donation_commitments.id_member,
donation_commitments.id_donation,
COUNT(commitments_paid.month_paid),
donation_commitments.months_commited
from
donation_commitments
join
commitments_paid on
commitments_paid.id_member = donation_commitments.id_member AND
commitments_paid.id_donation = donation_commitments.id_donation
where
donation_commitments.done <> 1
group by
donation_commitments.id_member,
donation_commitments.id_donation,
donation_commitments.months_commited

Alternatively, you could use group by 1, 2, 4

All the best with your donations,
Set
-curious about what you are working with

killerion wrote:
> I'm trying to create the following view:
>
> create view VIEW_COMMITMENTS_LEFT ( ID_MEMBER, ID_DONATION,
> TOTAL_MONTHS_PAID, MONTHS_COMMITED )
> as
> select
> donation_commitments.id_member,
> donation_commitments.id_donation,
> COUNT(commitments_paid.month_paid),
> donation_commitments.months_commited
> from
> donation_commitments,
> commitments_paid
> where
> (commitments_paid.id_member = donation_commitments.id_member) AND
> (commitments_paid.id_donation = donation_commitments.id_donation) AND
> (donation_commitments.done <> 1)
>
> I get the following error:
> Invalid expression in the select list (not contained in either an
> aggregate function or the GROUP BY clause).
>
> Now I assume this is due to the COUNT, since without it I can create
> the view, now any suggestions on how to get this to work or is there
> some other error I can't see?
>
> Jankowiak