There's no way you can do that in the level of Postgresql ? Or, using a function on Postresql to do that ?
Luis Sousa
Gezeala 'Eyah' BacuXo II wrote:
Hi!
I'm not using MySql I'm using Postgresql..
Here is my query..Can't combine them...I have to compute for the sum of the $poqty and $soqty..
// for so_qty $sql="SELECT CASE WHEN MAX(a.part_alternate_id) isNull THEN t.part_id ELSE ( SELECT part_alternate_child_id FROM part_alternate q WHERE q.part_alternate_id=( SELECT MAX(b.part_alternate_id) FROM part_alternate b WHERE b.part_alternate_parent_id=t.part_id)) END AS part_id, SUM(t.quantity) AS sodqty, t.part_id AS parent_id FROM temp_so_parts_sum t LEFT JOIN part_alternate a ON t.part_id=a.part_alternate_parent_id LEFT JOIN part p ON t.part_id=p.part_id WHERE userid=$users_id and part_model_id=$model_id GROUP BY t.part_id";
$rs=$conn->execute($sql); $result->set_resultset($rs); while(!$result->EOF()) { $temp=$result->get_row($rs); $soqty[$temp["part_id"]]=$temp["sodqty"]; $result->move_next(); }
$result=new pg_resultset;
//for poqty
$sql="SELECT pod_part_supp_id,part_id ,(SUM(pod_qty) * part_divisor) AS podqty
FROM vw_purchase_order_detail
WHERE po_lot_id IN (
SELECT lot_id
FROM lot
WHERE lot_model_id=$model_id AND lot_id
BETWEEN $from_lot_id AND $to_lot_id
)
AND po_model_id=$model_id
GROUP BY pod_part_supp_id,part_id,part_divisor ";
$rs=$conn->execute($sql);
$result->set_resultset($rs);
while(!$result->EOF()) {
$temp=$result->get_row($rs);
$poqty[$temp["part_id"]]=$temp["podqty"];
$result->move_next();
}
// got all the part_id's from this table/view..
$sql2="SELECT * FROM vw_part_supplier
LEFT JOIN model ON part_model_id=model_id
WHERE part_model_id=$model_id ORDER BY supplier_code, part_name, part_longcode";
$result=new pg_resultset;
$rs=$conn->execute($sql2);
$result->set_resultset($rs);
while(!$result->EOF()) {
$temp=$result->get_row($rs);
$supplier[$temp["part_id"]]=trim($temp["supplier_code"]);
$part_id[$temp["part_id"]]=$temp["part_id"];
$name[$temp["part_id"]]=trim($temp["part_name"]);
$code[$temp["part_id"]]=trim($temp["part_longcode"]);
$short[$temp["part_id"]]=trim($temp["part_shortcode"]);
$model[$temp["part_id"]]=$temp["model_id"];
$model_code[$temp["part_id"]]=trim($temp["model_code"]);
$model_desc[$temp["part_id"]]=trim($temp["model_desc"]);
$moq[$temp["part_id"]]=$temp["part_supp_min_qty"];
$result->move_next();
}
TIA!
Marie Gezeala M. Bacuño II Information Systems Department
Your choice: the red pill or the blue pill.
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php