表列拆分为sql中的两列? [英] Table column split to two columns in sql?

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

问题描述

在sql server中,我在表中只有一个列,我想在另一张表[new table]中将其变成两列.你能帮我吗?

In sql server, I have once column in the table, i want to make the column in two column, in the other table [new table]. Can you help me.

------------------------
  Type
  ------------------------
  UserDefine

  UserDefine

  AutoGenerate

  AutoGenerate

  UserDefine
 -------------------------

上面是我的一个表中的一列,现在我想将该列分成两张,如UserDefine和Autogenerate列在另一张表中

The above is my column in one of my table now i want to make the column in two like UserDefine and Autogenerate column in different table

  -----------------------------------
   UserDefine        | AutoGener      |
  ------------------------------------|
  UserDefine         |   AutoGenerate | 
                     |                |
  UserDefine         |   AutoGenerate |
 ---------------------------------------

像上面一样,请帮助我谢谢你.

Like the above, help me thank you.

推荐答案

尝试一下:

;WITH CTE
AS
(
  SELECT *, ROW_NUMBER() OVER(PARTITION BY [Type] ORDER BY [Type]) rownum
  FROM Table1
)
SELECT 
  MAX(CASE WHEN [Type] = 'AutoGenerate' THEN [Type] END) AS 'AutoGenerate',
  MAX(CASE WHEN [Type] = 'UserDefine' THEN [Type] END) AS 'UserDefine'
FROM CTE
WHERE Rownum <= 2
GROUP BY Rownum;

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

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