gpt4 book ai didi

mysql - 将两列排序为一列

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

假设我有一张 table - 人

id | First Name  | Last Name
-----------------------------'
1 AA BB
2 EE DD
3 CC FF

在这里,我想在 1 列中显示名字和姓氏。

Such that output would be 
----------------------
AA
BB
CC
DD
EE
FF

Can i also display it as
------------------
1 AA
1 BB
3 CC
2 DD
2 EE
3 FF

使用Mysql查询??

最佳答案

您正在寻找union all:

select first_name as name from persons union all
select last_name from persons
order by name;

编辑:

对于修改后的问题:

select id, first_name as name from persons union all
select id, last_name from persons
order by name;

关于mysql - 将两列排序为一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38099343/

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