将两个表中的两列合并为一个 [英] Merge two columns from two tables into one
问题描述
我正在尝试按两个不同表中的两个不同列进行排序. 这是情景:
I'm trying to sort by two different columns from two different tables. This is the situtation:
我有1个表"shops",其中有一个名为"shopy"的列,它是一个INT列. 另一个表称为"infra",并有一个名为"y"的列,该列也为INT.
I have 1 table 'shops' with a column called 'shopy', an INT column. The other table is called 'infra' and has a column called 'y', also an INT.
我想选择这两列并对它们进行排序,所以我将得到如下结果:
I would like to select these two columns and sort by them both, so I will get a result like this:
y
----------------
value from shopy
value from shopy
value from y
value from shopy
value from y
value from y
value from shopy
etc.
因此shopy和y会根据它们的值进行合并和排序.
So that the shopy and y get merged and sorted by the values of them.
我对您的问题:这可能吗?
My question to you: is this possible?
推荐答案
SELECT shopy as y FROM shops
UNION ALL
SELECT y FROM infra
ORDER BY y ASC
对于降序,请按y DESC编写Order.
for Descending order write Order by y DESC.
在
这篇关于将两个表中的两列合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!