gpt4 book ai didi

php - group_concat只显示一列?

转载 作者:行者123 更新时间:2023-11-29 22:17:22 24 4
gpt4 key购买 nike

我有一个像这样的数据库结构

 Car
- id
- carname
- image
- category
- status

Parts
- partid
- partname

CarParts
- carpartid
- carid(fk)
- partid(fk)
- amountid(fk)

Category
- id
- categoryname

Amount
- amountid
- amountvalue

这是我的查询:

SELECT group_concat(parts.partname) as parts FROM car left join  carparts on car.id = carparts.carpartid 
left join parts on parts.partid = carparts.carpartid
left join amount on amount.amountid = carparts.amountid where status = 1
group by car.id

但这仅显示部分,没有我想要的其他内容

  • 车名
  • 图像
  • 类别
  • 状态

最佳答案

您只需在 select 中传递列名称,请参见下面的示例:

SELECT 
group_concat(parts.partname) as parts,
car.carname,
car.image,
car.category,
car.status
FROM car
left join carparts on car.id = carparts.carpartid
left join parts on parts.partid = carparts.carpartid
left join amount on amount.amountid = carparts.amountid where status = 1
group by car.id

关于php - group_concat只显示一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31096351/

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