gpt4 book ai didi

php - 从 SQL 获取数据

转载 作者:行者123 更新时间:2023-11-29 10:10:35 26 4
gpt4 key购买 nike

我的数据库(MySql)中有一个“订单”表,我想在其中获取 4 个字段。

  1. 推销员
  2. 客户
  3. 插入日期
  4. qtd_order

但我只想要每个客户最后下的订单,所以我使用了这个 SQL 查询

SELECT 
salesman,
client,
insert_date,
qtd_order
FROM
`orders`
WHERE
salesman = 'daniel.costa'
GROUP BY
client
ORDER BY
insert_date

但它给了我第一个订单,而不是最后一个订单。

你能帮我拿一下吗?

最佳答案

您需要ORDER BY DESC从最近的开始......如果您只想要1个,您可以LIMIT 1 - 没有必要分组依据

SELECT salesman, client, insert_date, qtd_order FROM 
orders WHERE salesman = 'daniel.costa' ORDER BY insert_date DESC LIMIT 1

关于php - 从 SQL 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51032315/

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