SQL108. 组合 Products 表中的产品名称和 Customers 表中的顾客名称
描述
prod_name |
flower |
rice |
ring |
umbrella |
cust_name |
andy |
ben |
tony |
tom |
an |
lee |
hex |
prod_name |
an |
andy |
ben |
flower |
hex |
lee |
rice |
ring |
tom |
tony |
umbrella |
示例1
输入:
DROP TABLE IF EXISTS `Products`; CREATE TABLE IF NOT EXISTS `Products` ( `prod_name` VARCHAR(255) NOT NULL COMMENT '产品名称' ); INSERT INTO `Products` VALUES ('flower'), ('rice'), ('ring'), ('umbrella'); DROP TABLE IF EXISTS `Customers`; CREATE TABLE IF NOT EXISTS `Customers`( cust_name VARCHAR(255) NOT NULL COMMENT '客户姓名' ); INSERT `Customers` VALUES ('andy'),('ben'),('tony'),('tom'),('an'),('lee'),('hex');
输出:
an andy ben flower hex lee rice ring tom tony umbrella
Mysql 解法, 执行用时: 39ms, 内存消耗: 6460KB, 提交时间: 2022-03-02
select prod_name from Products union all select cust_name from Customers order by prod_name
Mysql 解法, 执行用时: 39ms, 内存消耗: 6492KB, 提交时间: 2022-03-06
select prod_name from Products union all select cust_name from Customers order by prod_name
Mysql 解法, 执行用时: 39ms, 内存消耗: 6504KB, 提交时间: 2022-03-03
select prod_name from Products union select cust_name as prod_name from Customers order by prod_name;
Mysql 解法, 执行用时: 39ms, 内存消耗: 6516KB, 提交时间: 2022-03-06
select prod_name from Products union select cust_name as prod_name from Customers order by prod_name
Mysql 解法, 执行用时: 39ms, 内存消耗: 6716KB, 提交时间: 2022-03-03
select * from Products union select * from Customers order by prod_name