将两个表中的两列合并为一个 [英] Merge two columns from two tables into one

查看:127
本文介绍了将两个表中的两列合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按两个不同表中的两个不同列进行排序. 这是情景:

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.

http://sqlfiddle.com/#!2/62884/1

这篇关于将两个表中的两列合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆