我可以将一个表行的结果合并为一行(带列)吗?
我本质上是想完成以下任务:
表 1:
MemberID | selection 1 | selection 2 | selection 3
-----------------------------------------------------------------------
12345 | A | |
12345 | | B |
12345 | | | C
转换为
表 2:
MemberID | selection 1 | selection 2 | selection 3
-----------------------------------------------------------------------
12345 | A | B | C
我认为“UNION”是可行的方法,但我认为这通常是为将列转换为行而保留的。
有什么想法吗?
I am essentially trying to accomplish this following:
Table 1:
MemberID | selection 1 | selection 2 | selection 3
-----------------------------------------------------------------------
12345 | A | |
12345 | | B |
12345 | | | C
Transforms into
Table 2:
MemberID | selection 1 | selection 2 | selection 3
-----------------------------------------------------------------------
12345 | A | B | C
Part of me thinks a 'UNION' is the way to go but this is normally reserved for columns into rows I believe.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的第一个想法是聚合技巧。没有数据的列是 NULL 还是空白?也许这些值排序在空白列的上方或下方。在这种情况下:
SELECT MAX(column1),MAX(column2),MAX(column3) FROM table GROUP BY MemberID;
My first thought is an aggregation trick. Are the columns without data NULL or just blank? Perhaps the values sort above or below the blank columns. In that case:
SELECT MAX(column1),MAX(column2),MAX(column3) FROM table GROUP BY MemberID;
我认为你试图在一张桌子上承担两项职责。 表
表 1、成员
表 2、选择
数据将如下所示:
1(成员)
表 2(选择)
那么您将获得所有选择,每行一个,
或者如果您只想要一个成员的选择
i'm thinking you're trying to have two responsibilities in one table. how about
table 1, members
table 2, selections
data would look like this:
table 1 (members)
table 2 (selections)
then you would get all selections, one per row, by doing
or if you just want the selections of one member