[英]MySQL - Split two columns into two different rows
I don't have any idea to create this sorry if it is a silly question. 如果这是一个愚蠢的问题,我不知道如何创建这个抱歉。
I have a table two teams and total watch and I will use this information later a different place so my idea concat this two column in one column but two different rows: 我有一个表两个团队和总监视,我稍后会在不同的地方使用这些信息,所以我的想法将这两列列在一列但两行不同:
HomeTeam AwayTeam Totalwatch
A B 100
A C 90
C A 80
D B 70
C E 50
Can I this 我能这样吗
Teams TotalWatch
A 100
B 100
A 90
C 90
C 80
A 80
D 70
B 70
C 50
E 50
I have a few columns so they will repeat as well. 我有几列,所以他们也会重复。
Just a note I know how can concat
in one-row use with concat
function I do not know how can I make with two rows 刚一说明,我知道如何
concat
同一个行使用concat
功能我不知道我怎样才能使两行
You can use UNION ALL
and an ORDER BY Totalwatch DESC
to get the results ordered according to Totalwatch
. 您可以使用
UNION ALL
和ORDER BY Totalwatch DESC
来获取根据Totalwatch
订购的结果。
SELECT HomeTeam AS Teams, Totalwatch FROM YourTable
UNION ALL
SELECT AwayTeam, Totalwatch FROM YourTable
ORDER BY Totalwatch DESC;
Simply use UNION ALL
: 只需使用
UNION ALL
:
SELECT *
FROM(
SELECT HomeTeam Teams,TotalWatch FROM Your_Table
UNION ALL
SELECT AwayTeam,TotalWatch FROM Your_Table
)D
ORDER BY TotalWatch DESC
Try this bro.. :) 试试这个兄弟.. :)
SELECT HomeTeam,Totalwatch
FROM YourTable
UNION ALL
SELECT AwayTeam,Totalwatch
FROM YourTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.