i have ds.unitprice , ord.qty need multiply. take sum of , add each of if there multiple linetotal's.
from there, take subtotal , multiply 1.1 (tax of 10%) , orders total.
i had issues subtotal, got work. totalprice still gives me 0, no matter do.
this query:
select *, sum(ds.unitprice*ord.qty) linetotal, sum(linetotal) subtotal, sum(subtotal*1.1) totalprice (orders ord, donuts ds, customers cust) left join customers on (cust.custid = ord.orderid) left join donuts on (ds.donutid = ord.donutid)
the problem referring column alias subtotal in definition of total. and, join conditions wrong.
if want totals per order:
select ord.orderid, sum(ds.unitprice * ord.qty) subtotal, sum(ds.unitprice * ord.qty * 1.1) totalprice orders ord join customers cust on cust.custid = ord.orderid join donuts ds on ds.donutid = ord.donutid group ord.orderid; if want totals orders:
select sum(ds.unitprice * ord.qty) subtotal, sum(ds.unitprice * ord.qty * 1.1) totalprice orders ord join customers cust on cust.custid = ord.orderid join donuts ds on ds.donutid = ord.donutid;
Comments
Post a Comment