删除sql中的重复列值

时间:2017-03-22 05:36:12

标签: javascript c# sql asp.net

我有这样的记录: -

1|Share Capital|Subscribed and paid up 
1|Share Capital|Capital Redemption Reverse
1|Share Capital|12% Debertures
1|Share Capital|plant and machinery
1|Share Capital|Shares in SBI
1|Share Capital|Stock in Trade
1|Share Capital|Provisions for taxation
1|Share Capital|Bill Receivable
1|Share Capital|BTPL LOAN

我只想立即写出Share Capital (第2列),将第3列作为子记录。有蚂蚁查询删除重复值,并给我输出如: -

1   Share Capital   Subscribed and paid up 
                    Capital Redemption Reverse
                    12% Debertures
                    plant and machinery
                    Shares in SBI
                    Stock in Trade
                    Provisions for taxation
                    Bill Receivable
                    BTPL LOAN

3 个答案:

答案 0 :(得分:0)

你可以做两件事

  1. 使用像MongoDB这样的No SQL数据库。这将允许您存储BSON文档,您可以将列表作为列,而SQL数据库只允许单个值。

  2. 规范化表格。这将涉及将表分成2个表并使用外键引用。

答案 1 :(得分:0)

你可以尝试这个

select distinct column1 ,column2,
STUFF( (select ' '+CONVERT(varchar,b.column3) from tbl_emp b 
where b.column1 = a.column1  and b.column2 = a.column2 
for xml path('')), 1, 1, '') from table

答案 2 :(得分:0)

试试这个

select Case when rownumber=1 then Column1 else null end as [Column1],
   Case when rownumber=1 then Column2 else '' end as [Column2],
   Column3
from 
(Select *,Row_number() Over(Partition by Column1 order by Column2) rownumber
 from YourTablename) c

结果:

enter image description here