gpt4 book ai didi

php - 如果所有产品都有库存显示或隐藏

转载 作者:行者123 更新时间:2023-11-30 21:51:24 24 4
gpt4 key购买 nike

我有一份订单上的产品 list ,我想检查这些代码是否有库存。如果我不需要隐藏订单,我可以显示订单上的所有代码。

我有两张 table 。一个是客户订单的产品,一个是商店有货的产品。

我希望此 MySql 连接仅显示我拥有所有产品的订单。如果我没有所有产品,请在列表中隐藏订单。

PHP

<?php while($row = $sql->fetch_array()){?>
<tr id="row<?php echo $row['id'];?>" style="height:20px">
<td><?php echo $row['id_comanda']; ?></td>
<td><?php echo $row['nume_produs']; ?></td>
<td><?php echo $row['qty']; ?></td>
<td><?php echo $row['stoc']; ?></td>
</tr>
<?php } $DBcon->close();?>

MySql

SELECT c.id_comanda
,c.nume_produs
,c.qty
,s.sku
,SUM(s.stoc) as stoc
FROM comenzi_tel_prod c
INNER JOIN stocuri_mentor s ON c.nume_produs = s.sku AND s.stoc >= c.qty
GROUP BY c.nume_produs


OR

SELECT c.*
,s.*
,SUM(stoc) AS stoc
FROM comenzi_tel_prod c
INNER JOIN stocuri_mentor s ON c.nume_produs = s.sku
AND stoc >= c.qty
GROUP BY c.id_comanda

数据库:

    comenzi_tel_prod 

+----+------------+-------------+-----+-------+------------+----------------------------------------+--------------+----------+
| id | id_comanda | nume_produs | qty | price | pret_engro | nume_ales | furnizor | subtotal |
+----+------------+-------------+-----+-------+------------+----------------------------------------+--------------+----------+
| 94 | 18 | K316546 | 2 | 17.85 | 16.16 | SUPER NET PURPLE 38cm x 38cm, EMGO, EA | Parts Europe | 523.719 |
| 95 | 18 | K316539 | 1 | 14.67 | 13.28 | SUPER NET-BLACK 38cm x 38cm, EMGO, EA | Parts Europe | 14.67 |
+----+------------+-------------+-----+-------+------------+----------------------------------------+--------------+----------+



stocuri_mentor

+----+---------+---------------------------------------+--------+------+---------------+------------+-----------+-----------+-------+--------------------+--------------+-----+---------------+
| id | sku | nume | den_um | stoc | stoc_rezervat | pret_engro | sim_clasa | den_clasa | brand | furnizor | pret_vanzare | gol | ean |
+----+---------+---------------------------------------+--------+------+---------------+------------+-----------+-----------+-------+--------------------+--------------+-----+---------------+
| 1 | K316539 | Arc ambreaj pornire Piaggio Ciao/Si | Buc | 1 | 0 | 0,87 | CIF | CIF | CIF | MOTO BIKE SHOP SRL | 1,04 | | 6686245374874 |
| 2 | K316546 | Paleta racire variator Piaggio/Gilera | Buc | 1 | 0 | 35,64 | CIF | CIF | CIF | MOTO BIKE SHOP SRL | 42,41 | | 6686245375017 |
| 3 | 11503 | Cui ponto scuter carburator PHBN/PHVA | Buc | 0 | 0 | 23,23 | CIF | CIF | Cif | MOTO BIKE SHOP SRL | 27,64 | | 6686245375093 |
| 4 | 11503 | Cui ponto scuter carburator PHBN/PHVA | Buc | 1 | 0 | 23,23 | CIF | CIF | Cif | MOTO BIKE SHOP SRL | 27,64 | | 6686245375093 |
| 5 | 0531z11 | Pinion z11 Garelli | Buc | 1 | 0 | 24,5 | CIF | CIF | CIF | MOTO BIKE SHOP SRL | 29,16 | | 6686245375246 |
| 6 | 11507 | Filtru holender Piaggio | Buc | 3 | 0 | 9,11 | CIF | CIF | CIF | MOTO BIKE SHOP SRL | 10,84 | | 6686245470590 |
+----+---------+---------------------------------------+--------+------+---------------+------------+-----------+-----------+-------+--------------------+--------------+-----+---------------+

最佳答案

试试这个

 `SELECT c.*
,s.*
,count(c.id) as instock_count
,totals.orders_total

FROM comenzi_tel_prod c
INNER JOIN (SELECT *, sum(stoc) as stoc_sum
FROM stocuri_mentor GROUP BY
sku ) s
ON c.nume_produs = s.sku
INNER JOIN (SELECT count(id) as orders_total, id_comanda
FROM comenzi_tel_prod
GROUP BY id_comanda ) totals
ON totals.id_comanda = c.id_comanda

WHERE stoc_sum >= c.qty
GROUP BY c.id_comanda
HAVING instock_count = orders_total`

关于php - 如果所有产品都有库存显示或隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47103474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com