表格1:
Id MyFK f_name l_name =========================== 1 100 John Doe 2 100 Little Timmy
表2:
Id MyFK item price =========================== 1 100 Car 200 2 100 Bike 100
在MySQL中,我如何生成这样的表:
Id MyFK f_name l_name item price ======================================== 1 100 John Doe Car 200 1 100 John Doe Bike 100 2 100 Little Timmy Car 200 2 100 Little Timmy Bike 100
CREATE TABLE person SELECT 1 AS Id, 100 AS MyFK, 'John' AS f_name, 'Doe' AS l_name UNION SELECT 2, 100, 'Little', 'Timmy'; CREATE TABLE vehicle SELECT 1 AS Id, 100 AS MyFK, 'Car' AS item, 200 AS price UNION SELECT 2, 100, 'Bike', 100; SELECT p.Id, p.MyFK, p.f_name, p.l_name, v.item, v.price FROM person p CROSS JOIN vehicle v;