Subject | Rép. : [firebird-support] group by in the right way... |
---|---|
Author | Maciek BOROWKA |
Post date | 2003-10-16T08:35:51Z |
Hello,
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
HTH
./Maciek
> I have a view like this ...As far as I can see, this is absolutely correct.. Well, for style purists,
> 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
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 wantIndeed.
> 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.
> What if I have other field in the customer table I want to view likeYes, you put it in the group by. No problem. Firebird will understand :+)
> customer credit limit, [snip] does it mean that I have to put all that
> in the group by clause...
HTH
./Maciek