mysql - Sums and subtotals in SELECT... HAVING result -


i'm trying sum of each customer's orders separately, i'm getting sum of all orders. doing wrong here?

select c.customernumber, sum( r.quantityordered * r.priceeach ) sum customers c, orders o, orderdetails r c.customernumber = o.customernumber , o.ordernumber = r.ordernumber group c.customernumber having count( o.ordernumber ) <=3 

first, should use join standardised way of writing syntax. makes easier read.

select c.customernumber, sum( r.quantityordered * r.priceeach ) sum customers c left join orders o      on  c.customernumber = o.customernumber left join orderdetails r on  o.ordernumber = r.ordernumber group c.customernumber having count( o.ordernumber ) <=3 

when use left join, give results of table customers, if dont have recods in orders , orderdetails.

give try!


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -