【问题标题】:How to add two values in mysql with invoice number is same and show as 1 entry in table?如何在 mysql 中添加两个发票号相同的值并在表中显示为 1 个条目?
【发布时间】:2019-08-31 14:39:22
【问题描述】:

我正在用 php 开发一个 pos。如果同时购买了两件商品,我将按产品保存销售产品,两者都使用与 MySQL 中的一行相同的发票号保存。我的问题是如何添加具有相同发票编号的两个条目的售价并在表格中显示为一个条目。 发票编号是自动生成的随机数。

productID sellingPrice invoiceNumber
   2          100          100
   1          20           100

作为

sellingPrice invoiceNumber
    120           100

【问题讨论】:

  • 请发布您到目前为止所尝试的内容
  • POS = 销售点系统。
  • 你可以做select sum(sellingPrice), invoiceNumber from table group by invoiceNumber
  • 是销售点

标签: php mysql


【解决方案1】:
SELECT sum(sellingPrice) as sellingPrice, invoiceNumber FROM tableName WHERE invoiceNumber = '100' group by invoiceNumber

【讨论】:

    【解决方案2】:

    使用分组方式:

    select sum(sellingPrice) as sellingPrice, invoiceNumber from tableName group by invoiceNumber

    【讨论】:

    • 它将汇总所有售价字段我只想汇总相同的发票编号字段而不是整个字段
    • $query = "SELECT * FROM sales WHERE (saleDate BETWEEN '$var' AND '$var1')"; $result = mysqli_query($mysqli,$query);
    • 我想总结相同的发票号码字段并显示所有其他字段,希望您能理解
    • @SohailFarooq 这很容易理解,为此您需要添加 where 子句并传递条件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2014-12-14
    • 2019-02-12
    • 1970-01-01
    相关资源
    最近更新 更多