首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

诡异的有关问题,大神帮忙

2012-05-20 
诡异的问题,大神帮忙SQL语句如下SQL codeSELECTSUM(VW_LSXHMX.SL*ISNULL(VW_LSXHMX.DJ_3,0) )AS CBJE FROM

诡异的问题,大神帮忙
SQL语句如下

SQL code
SELECT  SUM(VW_LSXHMX.SL*ISNULL(VW_LSXHMX.DJ_3,0) )  AS CBJE FROM [color=#FF0000](select DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,SUM(SL) AS SL,SUM(SL*CKJ) AS BZJE,sum(JE) AS JE,sum(BYZD9) AS BYZD9,LX from VW_LSXHMX_A  GROUP BY DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,LX )[/color] VW_LSXHMX left outer join (select distinct LSDJBH,RQ,SPDM,DM1,sum(SL) as SL,sum(JE) as JE,SUM(JE_2) AS JE_2 from VW_SDJSD where VW_SDJSD.JZ='1' GROUP BY  LSDJBH,RQ,SPDM,DM1) VW_SDJSD  on  VW_LSXHMX.DJBH=VW_SDJSD.LSDJBH AND VW_LSXHMX.SPDM=VW_SDJSD.SPDM AND VW_LSXHMX.DM1=VW_SDJSD.DM1,SHANGPIN,KEHU,DANWEI,FJSX1,FJSX2,FJSX3,FJSX4  WHERE VW_LSXHMX.SPDM=SHANGPIN.SPDM AND VW_LSXHMX.DM1=KEHU.KHDM AND SHANGPIN.DWMC = DANWEI.DWDM  AND SHANGPIN.FJSX1=FJSX1.SXDM AND SHANGPIN.FJSX2=FJSX2.SXDM AND SHANGPIN.FJSX3=FJSX3.SXDM AND SHANGPIN.FJSX4=FJSX4.SXDM  [color=#FFFF00]AND ((VW_LSXHMX.LX = '0') ) [/color]GROUP BY KEHU.KHDM,KEHU.KHMC,KEHU.BYZD8

运行后,提示我列名DJ_3无效。
当我把(
select DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,
SUM(SL) AS SL,SUM(SL*CKJ) AS BZJE,sum(JE) AS JE,sum(BYZD9) AS BYZD9,LX from VW_LSXHMX_A GROUP
BY DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,LX )这句话删除了之后,提示我列名LX无效,然后我也把这句话删除了AND ((VW_LSXHMX.LX = '0') )
我想请问,是什么原因造成列名无效的
我该怎么改,才能让他有效

[解决办法]
楼主在子查询时未提供[DJ_3]字段,如下代码,所以列名无效咯.
SQL code
select DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,SUM(SL) AS SL,SUM(SL*CKJ) AS BZJE,sum(JE) AS JE,sum(BYZD9) AS BYZD9,LX from VW_LSXHMX_A GROUP BY DJXZ,DJMC,DJBH,RQ,YSRQ,JZRQ,DM1,DM2,QDDM,YGDM,YS,JZ,JS,ZDR,YSR,JZR,JSR,BZ,SPDM,LX
[解决办法]
探讨
那我更不明白了。我查询的是VW_LSXHMX.DJ_3
和VW_LSXHMX_A.DJ_3有关系?

[解决办法]
顶AcHerat,其实问题很简单不诡异.

热点排行