查询班级中及格,一般,优秀的人数的sql语句
select a.ClassName,a.CourseName,sum(不及格) as 不及格,sum(差) as 差,sum(中等) as 中等,sum(好) as 好 ,sum(不及格)+sum(差)+sum(中等)+sum(好) as 班级总人数 from (select StudentID,ClassName,CourseName,1 as 不及格,0 as 差,0 as 中等,0 as 好 from StudentScore where ScoreRemark='fail' union all
select StudentID,ClassName,CourseName,0 as 不及格,1 as 差,0 as 中等,0 as 好 from StudentScore where ScoreRemark='low' union all
select StudentID,ClassName,CourseName,0 as 不及格,0 as 差,1 as 中等,0 as 好 from StudentScore where ScoreRemark='medium' union all
select StudentID,ClassName,CourseName,0 as 不及格,0 as 差,0 as 中等,1 as 好 from StudentScore where ScoreRemark='good' )a group by ClassName,CourseName
在这里需要注意的是要给某些字段加别名以示区别!
相关文档:
文章导航 SQL Server 2005 学习笔记系列文章导航
在SQl 2005 For XMl 简单查询(Raw,Auto,Path模式)(1) 里我们说了关于Path,Raw和Auto模式的用法,其实里面不仅仅 是这些简单的操作,还有一些其它的特性,比如说Type或OpenXml方法,sp_xml_preparedocument存储过程 等这些增加的东东,我们来一 ......
练手,每天查看别人的东西,不如自己总结好
1:replace 函数
第一个参数你的字符串,第二个参数你想替换的部分,第三个参数你要替换成什么
select replace('lihan','a','b')
&nb ......
写SQL的比写.NET程序的体验上差一等,没有智能提示,需要记住关键字,函数或者不断地Copy表字段名,自定义函数,存储过程之类的。不过在VS2010中,我们可以使用智能提示了,如下面几幅图所示: 在编辑器中, 输入 Shift + J (提示: VS2010 开发工具中标的是 Ctrl +J 其实应该是 Shift + J )就可以自动打开这个智能提 ......
select * from ((select bill.id billId,bach.riskRate risk,bach.assureRate assure from AcptBillInfo bill,AcptBach bach where bill.acptBatchId=bach.id and bill.rgctId=? )abach left outer join AcptSignMoney sig on abach.billId = sig.billId) ......
操作数据库结构的常用Sql
下面是Sql Server 和 Access 操作数据库结构的常用Sql,内容由海娃整理,不正确与不完整之处还请提出,谢谢。
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] dateti ......