【问题标题】:Get data from mysql according to column PHP [duplicate]根据列PHP从mysql获取数据[重复]
【发布时间】:2020-02-18 06:06:28
【问题描述】:

我有 mysql 表“booking”,我想根据 PaymentStatus 得到结果

订桌

id      shop_id      paymentStatus      amount      
1       2            1                  50      
2       2            1                  60
3       2            2                  40
4       2            2                  90

我想根据 PaymentStatus 获得预订总数(结果应该像 paymentStatus=1 的 2 个预订,paymentStatus=2 的 2 个预订) 和根据 PaymentStatus 的总金额(PaymentStatus=1 的总金额 110,paymentStatus=2 的总金额 130) 我该怎么做?

【问题讨论】:

  • 嗨,欢迎来到 stackoverflow。你试过什么?你检查过sql tutorial 上的 w3school 指南吗?

标签: php mysql


【解决方案1】:
SELECT paymentStatus, COUNT(id) total_bookings, SUM(amount) total_amount FROM `bookings` GROUP BY paymentStatus

【讨论】:

  • 这个答案缺少解释。 Stackoverflow 不是一堆 sn-ps,它是研究人员的教育资源。
猜你喜欢
  • 1970-01-01
  • 2014-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多