如何将多个输入字段组合为单个输出字段 [英] How to combine multiple input fields as single output field

查看:95
本文介绍了如何将多个输入字段组合为单个输出字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要来自几个输入字段的数据,并将它们视为

它们都是相同的字段。我不是很好描述,所以我会给你一个例子:


我有一张这样的桌子:
< br $>
名称收藏1:收藏2:收藏3:

鲍勃苹果香蕉樱桃

Ann Pear Peach Apple


我需要这样的输出:


名称水果

Bob Apple

Bob Banana

Bob Cherry

Ann Pear

Ann Peach

Ann Apple


有没有简单这样做的方法?我可以创建表格,然后使用

几个插入查询来拉取数据并填充表格(3

以上,但我已经有30个表格) ,但我在想必须有一个更简单的方法。

Hi,
I need to data from several input fields, and treat them as if
they were all the same field. I''m not describing this well, so I''ll
give an example:

I have a table like this:

Name Favorite 1: Favorite 2: Favorite 3:
Bob Apple Banana Cherry
Ann Pear Peach Apple

And I need output like this:

Name Fruit
Bob Apple
Bob Banana
Bob Cherry
Ann Pear
Ann Peach
Ann Apple

Is there an easy way to do this? I can create table, and then use
several insert queries to pull the data and populate the table (3
above, but 30 in the tables I''ve got), but I''m thinking there must be
an easier way.

推荐答案

Pythor写道:
Pythor wrote:



我需要从几个输入字段中获取数据,并将它们视为

它们是所有相同的领域。我不是很好描述,所以我会给你一个例子:


我有一张这样的桌子:
< br $>
名称收藏1:收藏2:收藏3:

鲍勃苹果香蕉樱桃

Ann Pear Peach Apple


我需要这样的输出:


名称水果

Bob Apple

Bob Banana

Bob Cherry

Ann Pear

Ann Peach

Ann Apple


有没有简单这样做的方法?我可以创建表格,然后使用

几个插入查询来拉取数据并填充表格(3

以上,但我已经有30个表格) ,但我想是必须有一个更容易的方式


Hi,
I need to data from several input fields, and treat them as if
they were all the same field. I''m not describing this well, so I''ll
give an example:

I have a table like this:

Name Favorite 1: Favorite 2: Favorite 3:
Bob Apple Banana Cherry
Ann Pear Peach Apple

And I need output like this:

Name Fruit
Bob Apple
Bob Banana
Bob Cherry
Ann Pear
Ann Peach
Ann Apple

Is there an easy way to do this? I can create table, and then use
several insert queries to pull the data and populate the table (3
above, but 30 in the tables I''ve got), but I''m thinking there must be
an easier way.



选择名称,favorite_1作为水果

来自mytable

联盟所有

选择名称,favorite_2为水果

来自mytable

union all

选择名称,favorite_3作为水果

来自mytable

订购1;


Art S. Kagel

select name, favorite_1 as fruit
from mytable
union all
select name, favorite_2 as fruit
from mytable
union all
select name, favorite_3 as fruit
from mytable
order by 1;

Art S. Kagel




Art S. Kagel写道:

Art S. Kagel wrote:

select name,favorite_1 as水果

来自mytable

联盟所有

选择名称,favorite_2为水果

来自mytable

联盟所有

选择名称,favorite_3作为水果

来自mytable

订购1;


Art S. Kagel
select name, favorite_1 as fruit
from mytable
union all
select name, favorite_2 as fruit
from mytable
union all
select name, favorite_3 as fruit
from mytable
order by 1;

Art S. Kagel



好​​的。谢谢。看起来我正在进行长时间的复制粘贴。

比我想到的创建表替代方案更好。

OK. Thanks. Looks like I''m in for a long period of Copy-Paste.
Better than the create table alternative I was thinking of, though.


是的 - 你最好不要硬编码收藏夹的数量,但

将表格移动到1NF。但是,如果再次出现这种情况,请看看Serge'的帖子标题为如何选择多列作为一个

列,以及

。讨论了如何使用VALUES构造来实现这样的

a情况。


--Jeff


Pythor写道:
Yes--you''re better off not hard-coding the number of favorites, but
moving the table to 1NF. However, should this come up again, take a
look at Serge''s posting titled "How do I SELECT multiple columns as one
column," which discusses the use of the VALUES construct for just such
a situation.

--Jeff

Pythor wrote:

Art S. Kagel写道:
Art S. Kagel wrote:

选择名称,favorite_1作为水果

来自mytable

联盟所有

选择名称,favorite_2为水果

来自mytable

union all

选择名称,favorite_3作为水果

来自mytable

订购1;


Art S. Kagel
select name, favorite_1 as fruit
from mytable
union all
select name, favorite_2 as fruit
from mytable
union all
select name, favorite_3 as fruit
from mytable
order by 1;

Art S. Kagel



好​​的。谢谢。看起来我正在进行长时间的复制粘贴。

比我想到的创建表替代方案更好。


OK. Thanks. Looks like I''m in for a long period of Copy-Paste.
Better than the create table alternative I was thinking of, though.


这篇关于如何将多个输入字段组合为单个输出字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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