Select (SELECT AVG(FieldB) FROM TableB) /fieldA AS FieldC From TableA 
where conditional

解决方案 »

  1.   

    strsql:='select (sum(chuqin_num)/( select * from zaiji where class_name= '''+edit4.Text+'''))*100 as 出勤率 from ' +tablename2;
    strsql:=strsql+' where kemu_name='''+combobox2.text+'''';
    strsql:=strsql+'and time='+edit1.text+'';
          
    这样写为什么不行
      

  2.   

    strsql:=strsql+'and time='+edit1.text+'';
     
    改为:
    strsql:=strsql+' and time='+QuotedStr(edit1.text);
    试试
      

  3.   

    表zaiji
         class-name       zaiji-num
           计算机1           40
           计算机2            50
    表计算机1班
        kemu-name      chuqin-num
         计算机网络          30
         计算机原理           20
      

  4.   

    strsql:='select (sum(chuqin_num)/( select top 1 zaiji_num from zaiji where class_name= '''+edit4.Text+'''))*100 as 出勤率 from ' +tablename2;
    这样好像也不大好
    zaiji 和tablename2是怎么联系起来的阿
      

  5.   

    table1
       field1
    table2
       field1
    select avg(field1)/
              (select field1
               from table2
               where condition)
    from table1
    这里是sql Server下利用Northwind做的试验,成功。
    SELECT AVG(UnitPrice) /
              (SELECT CategoryID
             FROM Categories
             WHERE CategoryID = 2) AS Expr1
    FROM Products
      

  6.   

    为什么运行会提示参数zaiji_num没有默认值