当前位置: 代码迷 >> ASP.NET >> 一条SQL语句.希望大哥哥门帮忙看看^
  详细解决方案

一条SQL语句.希望大哥哥门帮忙看看^

热度:2022   发布时间:2013-02-25 00:00:00.0
一条SQL语句........在线等,希望大哥哥门帮忙看看^_^!
If   Thing.SelectedItem.Value   <>   "-1 "   Then
                        Select   Case   Thing.SelectedItem.Text
                                Case   "迟到 "
                                        sql   =   "select   ClassName   as   班级,Stu_name   as   姓名,   Times   as   迟到     from   KQRecord   ,Class,Profession,Department   ,Affair   where   KQRecord.ClassID=Class.ClassID   and   Class.ProfessionID=Profession.ProfessionID   and   Profession.DepartmentID=Department.DepartmentID   and   Affair.AffairID=KQRecord.AffairID   and   Riqi   >   ' "   &   Sdate.Value   &   " '   and   Riqi <   ' "   &   Edate.Value   &   " '   and   AffairName= '迟到 ' "
                                Case   "早退 "
                                        sql   =   "select   ClassName   as   班级,Stu_name   as   姓名,   Times     as   早退     from   KQRecord   ,Class,Profession,Department   ,Affair   where   KQRecord.ClassID=Class.ClassID   and   Class.ProfessionID=Profession.ProfessionID   and   Profession.DepartmentID=Department.DepartmentID   and   Affair.AffairID=KQRecord.AffairID   and   Riqi   >   ' "   &   Sdate.Value   &   " '   and   Riqi <   ' "   &   Edate.Value   &   " 'and   AffairName= '早退 ' "
    End   Select
                End   If   这样我查询出班级、姓名、早退或者迟到的次数。
If   Thing.SelectedItem.Value   =   "-1 "   Then
                        sql   =   " "                
End   If   这里我想要查询出班级、姓名、迟到(次数)、早退(次数)、旷课(次数)这条语句怎么写啊`,还是要让   GridView动态的产生几列呢?如果要动态产生几列又是怎么弄啊`?(数据库中Affair表包括AffairID字段、AffairName字段,KQRecord表中也有AffairID字段)谢谢了``



------解决方案--------------------------------------------------------
帮顶,一起期待高手解决!!!!!!!!!!!
------解决方案--------------------------------------------------------
select ClassName as 班级,Stu_name as 姓名,迟到次数=sum (case AffairName when '迟到 ' then 1 else 0 end),早退次数=sum (case AffairName when '早退 ' then 1 else 0 end) from KQRecord ,Class,Profession,Department ,Affair where KQRecord.ClassID=Class.ClassID and Class.ProfessionID=Profession.ProfessionID and Profession.DepartmentID=Department.DepartmentID and Affair.AffairID=KQRecord.AffairID and Riqi > ' " & Sdate.Value & " ' and Riqi < ' " & Edate.Value & " ' " GROUP BY Stu_ID, Stu_Name, ClassName,AffairName

----------------我只写了迟到和早退,其他的自己照着写吧
------解决方案--------------------------------------------------------
SELECT CLASSNAME AS 班级,
STU_NAME AS 姓名,
  相关解决方案