You need to GROUP BY those fields NOT in the aggregate function. Like:
SELECT f.id,f.name,sum(p.price)
FROM fruit f
left join purchase p on f.id = p.fruit
where p.price is not null
group by f.id,f.name;
1, 'Apples', 2
2, 'Grapes', 6.5
4, 'Kiwis', 4
On 2015-10-23 04:15, Don Wieland wrote:
Hi ga
One more guess:
Try explicitly aliasing the fields of interest and using those aliases
exclusively throughout the rest of the expression.
SELECT
p.pk_ProductID as pid,
p.Description as dsc,
SUM(i.Quantity) as totl
FROM invoice_invoicelines_Product p
JOIN invoice_InvoiceLines i ON pid = i.fk_Prod
> On Oct 22, 2015, at 2:41 PM, Michael Dykman wrote:
>
> I'm not at a terminal but have you tried grouping by p.pk_ProductID instead
> of i.fk...? It is the actual value you are selecting as well as being on
> the primary table in the query.
Yeah I tried that - actually the SUM I need is on the
I'm not at a terminal but have you tried grouping by p.pk_ProductID instead
of i.fk...? It is the actual value you are selecting as well as being on
the primary table in the query.
On Thu, Oct 22, 2015, 5:18 PM Don Wieland wrote:
> Hi gang,
>
> I have a query:
>
> SELECT
> p.pk_ProductID,
> p.De
Hi gang,
I have a query:
SELECT
p.pk_ProductID,
p.Description,
i.Quantity
FROM invoice_invoicelines_Product p
JOIN invoice_InvoiceLines i ON p.pk_ProductID = i.fk_ProductID AND
i.fk_InvoiceID IN (1,2,3)
WHERE p.pk_ProductID IN (1,2,3);
It produces a list like the following:
1,Banana,3