我要選擇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可以解決的是better.Thank你。
什麼是 '這是行不通的。'意思?最後一個查詢中有錯誤的圓括號。 –