Re: How to sum and group by?
Master: Customer Information
Id = BigInt
Name = varchar
Detail: Orders Information
Id = BigInt
CustomerId = BigInt (related to Master table)
InvoiceNumber = Int
Year = int
Price = decimal
Is this what you mean?
select c.id, d.year, sum(d.price) as total
from customers c
join details d on c.id=d.customerid
group by c.id, d.year;
BTW your id, customerid and year columns are overkill. You don't expect to have 9 quintillion customers or sales, probably smallint unsigned would do, and you'll never get past a year that fits in a smallint unsigned.
Subject
Written By
Posted
Re: How to sum and group by?
January 16, 2018 09:51AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.