论坛里看到的一个SQL问题及解答
问题:
有一个分数表
id classid,score
1 01 120
2 01 128
3 02 98
4 04 134
5 04 78
现在要统计 各班score >120,和大于90分的人数
达到如下效果
classid >120 >90
01 10 29
02 9 32
03 0 20
答案:
select
classid,
sum
(
case
when
score
>
120
then
1
else
0
end
)
as
[
>120
]
,
sum
(
case
when
score
>
90 and score <=120
then
1
else
0
end
)
as
[
>90
]
from
tb
group
by
classid
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......
1.使用 ESCAPE 关键字定义转义符。 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。例如,要搜索在任意位置包含字符串 5% 的字符串,请使用: WHERE ColumnA LIKE '%5/%%' ESCAPE '/'
2.ESCAPE 'escape_character' 允许在字符串中搜索通配符而不是将其作为通配符使用。 escape_character 是放在通配符前 ......
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB,comobj, OleServer,
ExcelXP;
type
TForm1 = class(TForm)
ADOConn: TADOConnection;
& ......
最先希望使用datatable.columns种所含有的属性直接获取相关信息,可测试后发现,除了字段名和字段类型,其他数据一概找不到。
GOOGLE网上很多种方法,其中最直接的是直接查询SQLSERVER的information_schema.colums视图,从中直接获取信息,不过后来又发现,虽然数据时全了,可是需要通过很复杂的方法(sys.all_columns sys ......