select sum1 ,sum2 ,sum3 from (select Company_Name,Tax_Type,sum(Tax_number) sum1 from table1)
你用的是什么数据库,这种语法SQL server是不行的。

解决方案 »

  1.   

    sql语句拿出来在查询器里测试一下
      

  2.   

    你想用的同嵌套子查询,必须是下面这种格式:
    select * from something where(子查询(子查询));把你上面的改成:
    select sum1,sum2,sum3 from table2 where sum1 in (select company_name,tax_type,sum(tax_number) from table1)
      

  3.   

    检查一下你的数据库连接字符串及SQL语句
      

  4.   

    我用的是Oracle,我在中间放了个断点,把这个SQL放到立即窗口中,把运行的结果拿出来放到SQLPLUS中,完全没有问题的。
    大家认为一定是在字符串中出现问题的吗?
      

  5.   

    楼上的你的Sql语句也有问题的,对于多列查询不能用in,应该用exists,但这样性能及差。
    select cast(0 as bit) as Ifpubs,ResourceID,subid,Acronym,UseCount, AllCount,enddate from @table as tab
    where not exists (select  *  from Metalallitem where AllWeekId=0 and tab.ResourceID=Metalallitem.ResourceID and tab.subid=Metalallitem.subid)
    order by ResourceID,subid
      

  6.   

    "select sum1 ,sum2 ,sum3 from (select Company_Name,Tax_Type,sum(Tax_number) sum1 from table1 where substr(to_char(Tax_Time),1,6)=substr(to_char(sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_1, (select Company_Name,Tax_Type,sum(Tax_number) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_2, (select Company_Name,Tax_Type,sum(Tax_Number) sum3 from table1 where Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_3 where tab_1.Company_Name = tab_2.Company_Name(+) and tab_1.Tax_Type = tab_2.Tax_Type(+) and tab_1.Company_Name = tab_3.Company_Name(+) and tab_1.Tax_Type = tab_3.Tax_Type(+);"
    上面这句话是我从调试窗口拉出来的,这句话在Oracle中运行是没有问题的。
      

  7.   

    ConnStr = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=system;Password=put_ruan;Data Source=heda;"会不会是连接字符串的问题啊,你可以通过控件创建一个字符串进行测试
      

  8.   

    奇怪我换了个简单的就可以了。难道是我的语句有问题,但是我是用调试出来的语句放在Oracle中是没有问题的啊?昏倒了%……—*()
      

  9.   

    把你的SQL查询字符串用Response.Write输出来再检查并运行一下看看,错误肯定在你的SQL语句中,这么长的语句看得人头昏眼花!:)
      

  10.   

    Response.write 出来的是:select sum1 ,sum2 ,sum3 from (select Company_Name,Tax_Type,sum(Tax_number) sum1 from table1 where substr(to_char(Tax_Time),1,6)=substr(to_char(sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_1, (select Company_Name,Tax_Type,sum(Tax_number) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_2, (select Company_Name,Tax_Type,sum(Tax_Number) sum3 from table1 where Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_3 where tab_1.Company_Name = tab_2.Company_Name(+) and tab_1.Tax_Type = tab_2.Tax_Type(+) and tab_1.Company_Name = tab_3.Company_Name(+) and tab_1.Tax_Type = tab_3.Tax_Type(+);
    我把他Copy到Oracle中执行结果没有错我想实现的功能是:
    http://expert.csdn.net/Expert/topic/2661/2661232.xml?temp=.9875605http://expert.csdn.net/Expert/topic/2661/2661955.xml?temp=3.565615E-02
    就是想把一张表格中查到的结果放到一个DataGrid中。
      

  11.   

    格式化一下,效果好点:select sum1 ,sum2 ,sum3 from 
    (select Company_Name,Tax_Type,sum(Tax_number) sum1 from table1 where substr(to_char(Tax_Time),1,6)=substr(to_char(sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_1, (select Company_Name,Tax_Type,sum(Tax_number) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_2, (select Company_Name,Tax_Type,sum(Tax_Number) sum3 from table1 
    where Company_Name like '%北京%' group by Company_Name,Tax_Type) tab_3 where tab_1.Company_Name = tab_2.Company_Name(+) and tab_1.Tax_Type = tab_2.Tax_Type(+) and tab_1.Company_Name = tab_3.Company_Name(+) and tab_1.Tax_Type = tab_3.Tax_Type(+);
      

  12.   

    TMD,问题解决.最后面的";"多了。奶奶的.