gpt4 book ai didi

mysql - 输出两个表的表名及其他属性

转载 作者:行者123 更新时间:2023-11-29 07:08:31 25 4
gpt4 key购买 nike

如果我有两个这样的表:

-- -----------------------------------------------------
-- Table `mydb77`.`supplier`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb77`.`supplier` (
`sp_id` INT(11) NOT NULL AUTO_INCREMENT,
`sp_company` VARCHAR(45) NULL DEFAULT NULL,
`sp_location` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`sp_id`));

-- -----------------------------------------------------
-- Table `mydb77`.`customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb77`.`customer` (
`cu_id` INT(11) NOT NULL AUTO_INCREMENT,
`cu_name` VARCHAR(45) NULL DEFAULT NULL,
`cu_title` VARCHAR(15) NULL DEFAULT NULL,
`cu_location` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`cu_id`);

如何获得以下输出:

enter image description here

按名称排序。

这些表具有不同数量的列。

最佳答案

您可以使用union all做您想做的事情:

select 'supplier' as tablename, sp_id as id,
sp_company as name, sp_location as location
from supplier
union all
select 'customer', cu_id, cu_company, cu_location
from customer
order by 3;

关于mysql - 输出两个表的表名及其他属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40707519/

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