划分一列sql表 [英] divide one column of sql table

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

问题描述

大家好,

我们可以将一列sql表分成3列吗?

就像我有一个名为Marks的列。

我想在列名Marks下输入10号,12号毕业标记。

即我有一个名为''Marks''的主列,我想创建名为''的辅助列它下面的第10个',''12'',''毕业'。

有可能吗?

如果是,那么怎么样?

Hi all,
Can we divide a column of sql table into 3 more columns?
Like i have a column named Marks.
And i want to enter the marks of 10th, 12th, graduation under the column name Marks.
i.e. I have a primary column named ''Marks'' and i want to create secondary columns named ''10th'', ''12th'', ''graduation'' under it.
Is it possible?
If yes then how?

推荐答案

Namaskar(嗨),



你可以试试这个

Namaskar(Hi),

You can try this
1)create table emp(FirstName)
2)insert the values in that suppose i have 7 values
Sandeep
Prasad
Sharad
Sachin
Ravi
Ashish
Mangesh



现在我想把我的FistName列分成4列然后


and now i want to split my FistName column into 4 columns then

3);WITH T
     AS (SELECT firstname,
                ( ROW_NUMBER() OVER (ORDER BY (SELECT 0)) - 1 ) / 4 AS Row,
                ( ROW_NUMBER() OVER (ORDER BY (SELECT 0)) - 1 ) % 4 AS Col
         FROM   tempemp)
SELECT [0] AS Column1,
       [1] AS Column2,
       [2] AS Column3,
       [3] AS Column4
FROM   T PIVOT (MAX(firstname) FOR Col IN ([0], [1], [2], [3])) P 
ORDER BY Row



!!!!!!!!!!!!!!!!输出将是!!!!!!!!!!!!!!! !!!


!!!!!!!!!!!!!!!!OUTPUT WILL BE!!!!!!!!!!!!!!!!!!

Column1  Column2  Column3   Column4
Sandeep	 Prasad	  Sharad    Sachin
Ravi	 Ashish	  Mangesh   NULL


是的,你可以。您可以选择相同的列三次,但是对该值执行操作以提取您的三个值,并将它们命名为您喜欢的任何值。
yes, you can. You can select the same column three times, but perform operations on that value to extract your three values, and name them anything you like.


您好,



我能理解你的要求。我建议你按照以下步骤进行操作。



1.您可以将列名保持为标记。

2。创建另一个可以包含您的第10个,第12个刻度标记的表。在此表中保留一个ID列,并将主键设置为该列。

3.在主表中,将第二个表的ID列设置为Mark列的外键。



通过这种方式,您可以在一列下拥有多个列。



参考此链接这将有助于您除以列值。

将列分成多个



谢谢
Hi,

I can understand your requirement. I can suggest you to go like the following.

1. You can keep your column name as mark as it is.
2. Create another table that can contain your 10th, 12th, graduation marks. Keep one ID column in this table and set primary key to that column.
3. In your main table make the ID column of the second table to foreign key to Mark column.

In this way you can able to have more then one column under a single column.

Refer this link this will help you in dividing the column values.
Divide a column into many

Thanks


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

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