首页 > 请教一个mysql三表关联查询的问题

请教一个mysql三表关联查询的问题

orderlogistics(物流信息表)
orderlogistics_id:自增id
userid:用户id,
ordercode:订单号
logistics:物流公司,字符型
logisticsid:物流号
yunfei
status

customer(客户表)
customer_id:自增id
userid:用户id,
username
nicename
pro,city,dist,addr:收货地址,这里是4个字段,都是字符型,直接写入的省市区县地址的中文
mobile

order(订单表)
order_id:自增id
productname:商品名称
inprice
num
unit
incurrency
other
exchange_rate
cost
outprice
profit
ordercode:订单号
userid:用户id,
customerid:自增id
orderdate
status

有以上三个表,需要列出订单列表,订单列表所用到的字段如下:order_id ,username,nicename,mobile,pro,city,dist,addr,logistics,logisticsid,status,cost,outprice,other,profit

请问该如何写sql查询,sql不精,让各位见笑了。


将order(订单表)选择为你的主表,
1、里面有customerid可以去joincustomer(客户表)去查用户信息【username,nicename,mobile,pro,city,dist,addr】,
2、里面有ordercode订单号可以joinorderlogistics(物流信息表)去查物流信息


报错了:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from order a left join customer b on a.customerid = b.customerid left join order' at line 1


select a.order_id ,a.cost,a.outprice,a.other,a.profit,a.status,b.username,b.nicename,b.mobile,b.pro,b.city,b.dist,b.addr,c.logistics,c.logistics, from order a left join customer b on a.customerid = b.customerid left join orderlogistics c on b.userid = c.userid

【热门文章】
【热门文章】