我试图在ms sql server的查询中导出以下数据进行访问,它表示错误“字段wkid已存在于表结果中”
当我尝试使用sql查询分析器执行相同的操作时,它没有给出任何错误。我在网格中得到结果
Select a.wkid,a.stid,a.pfid,pf.pfname,a.modid,mm.md,a.catid,
[sp],revenue,profit,wkid from
(select stid,modid,pfid,catid,
[sp],revenue,profit,wkid
from dbo.modspsal
where wkid >= 200934 and wkid <= 201033 and
catid in (20001,20002,20003,20004,20005,20006)) as a
left join mml mm on
mm.modid=a.modid
left join (select distinct pfid,[pf name] as pfname from mml) as pf
on pf.pfid=a.pfid
order by a.wkid,stid,catid,a.pfid,a.modid
答案 0 :(得分:2)
当您导出到Excel时,您需要具有唯一的列名称。你有wkid指定2.
Select a.wkid,--HERE
a.stid,
a.pfid,
pf.pfname,
a.modid,
mm.md,
a.catid,
[sp],
revenue,
profit,
wkid --HERE
from (
select stid,
modid,
pfid,
catid,
[sp],
revenue,
profit,
wkid
from dbo.modspsal
where wkid >= 200934
and wkid <= 201033
and catid in (20001,20002,20003,20004,20005,20006)
) as a left join
mml mm ON mm.modid=a.modid left join
(
select distinct
pfid,
[pf name] as pfname
from mml
) as pf on pf.pfid=a.pfid
order by a.wkid,stid,catid,a.pfid,a.modid
删除最后一个wkid,你应该没事。