order表
order_id name
1 小明
2 小红
expend表
expend_id order_id cost date
1 1 100 2017-01-01
2 1 200 2017-02-02
3 2 200 2017-01-01
4 2 250 2017-01-02
小白想请教如何连表查询能得到这样的数据 有朋友会么?主要是一对多 会返回 多条order表信息的数据 查出来是多个B表的数据 应该怎样才能处理成以下的数据捏
array(
[0]=>array(
'order_id'=>1,
'name'=>小明,
'2017-01-01'=>100,
'2017-02-01'=>200,
),
[1]=>array(
'order_id'=>2,
'name'=>小红,
'2017-01-01'=>200,
'2017-02-01'=>250,
)
)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我想问日期为什么是作为跟name,order_id的同级键名,这样用起来不方便吧
select a.order_id,a.name,b.cost,b.date from order as a left join expand on a.order_id=b.order_id group by order_id;
这种把日期当作key,mysql做不到的吧,只能后期处理吧