多维度mysqlselect?

multi dimensional mysql select?

table: car_profile
carid, carname, caryear, cartype

table: user_profile
userid, username, useremail

table: user_car
id, carid, userid, status
FC: carid, userid

一个carid可以有多个userid在tableuser_car(一辆车可以多人使用)

给定一个carid,我想selectcaryearcartype[userid, username, useremail]。括号内的那个本身应该是一个数组,因为多个 userid 是可能的。我不确定这是否可行?

SELECT 可以 return 单个值、一行值或 table 行。没有更高维度的选择。下面,多个 useridusernameuseremail 将显示在不同的行中。

SELECT cp.caryear, cp.cartype, up.userid, up.username, up.useremail
FROM car_profile as cp
LEFT JOIN user_car as uc
ON uc.carid = cp.carid 
LEFT JOIN user_profile as up
ON uc.userid = up.userid
WHERE cp.carid = carid
ORDER BY cp.caryear, cp.cartype