我想选择SQL Server数据类型和名称,但它有复制列,这是我的SQL:
with typesum
as
(
select sc.xtype,sc.[length],st.name
from syscolumns sc,systypes st
where sc.xtype=st.xtype
group by sc.xtype,sc.[length],st.name
)
select distinct tsa.xtype,tsb.name,tsb.[length]
from typesum tsa left join typesum tsb
on tsa.xtype=tsb.xtype
它有许多复制数据。
我用另一种方式:
select distinct (sc.xtype,st.name) from syscolumns sc
left join systypes st
on sc.xtype=st.xtype
group by sc.xtype,st.name
它不起作用。
我的问题是:如何通过不同的一列来区分多个列并获取唯一数据?结果有10列,我希望将第1列与标准区分开,并删除其他列数据。
例如:
1 1
1 1
2 2
2 2
结果是:
1 1
2 2
也许样本sql可以解决更好。谢谢。
答案 0 :(得分:3)
您不需要group by
和distinct
无论
select distinct sc.xtype,st.name
from syscolumns sc
left join systypes st
on sc.xtype=st.xtype
或
select sc.xtype,st.name
from syscolumns sc
left join systypes st
on sc.xtype=st.xtype
group by sc.xtype,st.name
应该都有效