回 帖 发 新 帖 刷新版面

主题:求sql语句

表1                             表2
学号|姓名|                   学号|评定|  //每次都会评定,打分:优,良,中,及格
实现以下查询:统计每个人的情况,如:统计个数
学号| 姓名| 优| 良| 中| 及格
11    XX    5   3   2    0 

回复列表 (共5个回复)

沙发

select * ,

优=(select count(*) from 表2 where 表2.学号=表1.学号 and 表2.评定='优'  ),

良=(select count(*) from 表2 where 表2.学号=表1.学号 and 表2.评定='良'  ),

中=(select count(*) from 表2 where 表2.学号=表1.学号 and 表2.评定='中'  ),

差=(select count(*) from 表2 where 表2.学号=表1.学号 and 表2.评定='差'  )


from 表1

板凳

select * ,

。。。优=(select 。。。
这里好象不能这样写啊,我调试过了

3 楼

我语句这样写的,但不行啊
with query3 do
  begin
  sql.Clear;
  sql.Add('select xh 学号,xm 姓名,bj 班级,优=(select count(*) from t_report1 where (t_report1.xh=t_info.xh and t_report1.pd="优"))');
  sql.Add('良=(select count(*) from t_report1 where (t_report1.xh=t_info.xh and t_report1.pd="良"))');
  sql.Add('中=(select count(*) from t_report1 where (t_report1.xh=t_info.xh and t_report1.pd="中"))');
  sql.Add('及格=(select count(*) from t_report1 where (t_report1.xh=t_info.xh and t_report1.pd="及格"))');
  sql.Add('差=(select count(*) from t_report1 where (t_report1.xh=t_info.xh and t_report1.pd="差")) from t_info');
  open;
  end;
  except
  showmessage('程序查询失败');
  end;

4 楼

查询语句可以在查询分析器中执行。。没有错误。

这个错误只是你在在delphi中写sql语句的语法错误。自己慢慢整理吧。。

5 楼

那只是一个简单地SQL语句调用,要想在程序中运行通过的话.还得将语法从新整合一下.这样在delphi 就可以编译通过了.

我来回复

您尚未登录,请登录后再回复。点此登录或注册