gpt4 book ai didi

sql - MySQL - 显示所有排列?

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:32 24 4
gpt4 key购买 nike

表 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;

关于sql - MySQL - 显示所有排列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3475766/

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