gpt4 book ai didi

php - 如何在一张表mysql php中加入行

转载 作者:行者123 更新时间:2023-11-29 20:18:55 25 4
gpt4 key购买 nike

如果表中的行像这样,如何连接一个表中的行

命名表1

id uid uid1  name qty  price status
1 002 null null null null order
2 002 03002 abc null 10000 cart
3 002 null abc 8 10000 finish

并从输出连接中获取 1 行,如下所示

3  002 03002 abc 8 10000 finish 

*主要是最后一条记录

谢谢

最佳答案

我认为您实际上并不想进行JOIN,并且您的问题并不完全完整并且没有多大意义,但无论如何,请给它一个去让我知道结果是什么。

select max(id) as id
, uid
, max(uid1) as uid1
, max(name) as name
, sum(qty) as qty
, max(price) as price -- or sum(price)?
, max(
CASE WHEN status="finish" THEN "3 - finish"
CASE WHEN status="cart" THEN "2 - cart"
CASE WHEN status="order" THEN "1 - order"
END
) as status -- this will give you the last step that the user reached. If there are more steps possible then this could be a problem
from TABLE1
group by uid -- assuming this is a transaction id or something?

关于php - 如何在一张表mysql php中加入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39585240/

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