Subject Rép. : [firebird-support] group by in the right way...
Author Maciek BOROWKA
Hello,

> I have a view like this ...
> create view invoice_with_cust_details
> (cust_id, cust_type, total_amount)
> as
> select m.cust_id, d.cust_name, d.cust_type, sum(m.total_amount)
> from invoice m left join customer d on m.cust_id = d.cust_id
> group by m.cust_id, d.cust_name, d.cust_type

As far as I can see, this is absolutely correct.. Well, for style purists,
I would probably invert the ordrer of join (because your solution
wouldn't include customers without invoices) :

select d.cust_id, d.cust_name, d.cust_type, sum(m.total_amount)
from customer d left join invoice m on d.cust_id = m.cust_id
group by d.cust_id, d.cust_name, d.cust_type


> I want to place the m.cust_id in the group by clause because I want
> to total_amount of invoice for each customer, but since in the view
> I want to be able to display the cust_name and cust_type I was force
> to include the d.cust_name and d.cust_type in the group by clause.

Indeed.

> What if I have other field in the customer table I want to view like
> customer credit limit, [snip] does it mean that I have to put all that
> in the group by clause...

Yes, you put it in the group by. No problem. Firebird will understand :+)

HTH
./Maciek