mysql - Sql Join Three table -


this question has answer here:

here table ..and want output:

pid | pname | custname | quantity | total base price | sale price | profit 

schema:

create table customers (     cid int,     cname varchar(1000),     cg varchar(1000) )  create table prod (     pid int,     pname varchar(1000),     baseprice int,     saleprice int )  create table orders (     oid int,     custid int,     pid int,     quantity int,     odate date ) 

how write query this?

--pid | pname | custname | quantity | total base price | sale price | profit select o.pid, p.pname, c.cname custname, sum(o.quantity) quantity,  sum(p.baseprice) 'total base price', sum(p.saleprice) 'sale price',  sum(p.baseprice) - sum(p.saleprice) profit -- change math need orders o join prod p on o.pid = p.pid join customers c on o.custid = c.cid group o.pid, p.pname, c.cname 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -