规范化表上的数据
我需要帮助来转换表上的数据,将一系列列减少为一个列。下面是一个示例:
Frequency_1 integer,
Frequency_2 integer,
Frequency_3 integer,
Frequency_4 integer,
这些列当前保存 1 或 0。只有一列保存 1。
新列应定义为
Frequency integer
此新列应保存 1 到 4 之间的值,具体取决于哪一旧列具有其值= 1.
你能建议一个 SQL 命令来完成这个任务吗?
I need help to transform data on a table, reducing a series of columns to one single column. An example follows below:
Frequency_1 integer,
Frequency_2 integer,
Frequency_3 integer,
Frequency_4 integer,
These columns currently hold 1 or 0. Only one column will hold 1.
The new column should be defined as
Frequency integer
And this new column should hold a value between 1 and 4, depending on which of the old columns had its value = 1.
Could you suggest an SQL command to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你愿意的话,你可以想出更复杂的东西,但为什么不这样做呢?
要实际进行更改,您可以先创建列,更新新列中的值,然后删除旧列。
You could come up with something more complicated if you want, but why not just do this?
To actually make the change, you can create the column first, update the value in the new column, then delete the old columns.
像这样:
或这样:
Like this:
or this: