SQL command to calculate from Amount and ID, total weight -
table: orderproducts
orderid quantity weight ----------------------------------- 4 5 0.1 4 2 0.5 5 3 2.5 5 7 0.9
1) following sql command, total weight calculated correctly, product quantity ignored. how can expand sql command query quantity of product?
select orderid, sum (weight) totalweight orderproducts group orderid
now have orderid 4 value (totalweight) => 0.6
must correctly => 1.5
2) in addition, sql command "where" (where other_table.status = "finish") extend table. not work. :-(
select orderid, sum (weight) totalweight orderproducts other_table.status = "finish" group orderid
query:
select orderid, sum(weight*quantity) totalweight orderproducts join othertable b on (b.orderid=b=id) b.status = "finish" group orderid
Comments
Post a Comment