mysql - Sql Join Three table -
this question has answer here:
- joining 3 tables using mysql 8 answers
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
Post a Comment