易截截图软件、单文件、免安装、纯绿色、仅160KB

论坛里看到的一个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


相关文档:

SQL中escape的主要用途

1.使用 ESCAPE 关键字定义转义符。 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。例如,要搜索在任意位置包含字符串 5% 的字符串,请使用: WHERE ColumnA LIKE '%5/%%' ESCAPE '/'
2.ESCAPE 'escape_character' 允许在字符串中搜索通配符而不是将其作为通配符使用。 escape_character 是放在通配符前 ......

Delphi Excel to Sql Server

 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;
& ......

获取SQL Server服务器列表的几种方法

一、 SQL DMO 描述:SQL Distributed Management Objects(SQL分布式管理对象),存在于SQLDMO.dll文件中,实际上是一个COM 对象,通过调用SQL DMO的ListAvailableSQLServers方法取得。 列表类型:列举装有“客户端”和“服务端”的计算机。 适用条件:装有 SQL Server,且有SQLDMO.dll文件。 速度:中 调用示例:GetS ......

SQL Server

查询 card 的记录为两次以上的 card,记录数:
select count(card), card from TableName group by card having count(card) > 1
级联更新,级联删除:
ColumnName type not null constraint FK_Name foreign key(ColumnName) references PrimaryTable(ColumnName) on update/delete cascade
自动计算列:
create tabl ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号