我正在研究医院项目。我的问题是:我有两张桌子(1)。股票和(2)。的信息。
库存表包含药品总库存。
详细信息表包含totalstockquantity - soldstock数量。
我试过这个代码:
$result=mysql_query(
"SELECT ((stock.quantity)-details.quantity) AS sub,
stock.id AS id,
stock.name AS name,
stock.type AS type,
stock.batch_no AS batch,
stock.quantity AS quantity,
stock.exp AS exp
FROM stock
INNER JOIN details on stock.name=details.medicine ");
?>
但它会给出同一个id的多个结果。
答案 0 :(得分:-1)
SELECT stock.quantity - (select sum(details.quantity) from details where stock.name=details.medicine) AS sub,
stock.id AS id,
stock.name AS name,
stock.type AS type,
stock.batch_no AS batch,
stock.quantity AS quantity,
stock.exp AS exp
FROM stock