论坛里看到的一个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
相关文档:
Next up in the Inside the Storage Engine series is a discussion of page structure. Pages exist to store records. A database page is an 8192-byte (8KB) chunk of a database data file. They are aligned on 8KB boundaries within the data files, starting at byte-offset ......
在20世纪70年代初期,IBM研究员E. F. Codd博士开创性地研究开发了关系数据模型产品SEQUEL,即结构化英语查询语言(Structured English Query Language)。SEQUEL最终变成了SQL,或结构化查询语言(Structured Query Language,SQL)。
IBM及其他关系数据库的开发厂商都希望有一套能访问并操纵关系数据库的标准化方 ......
查询 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 ......
我发现自己理解起sql语句来很困难,今天看了一本书,顿时茅塞顿开,贴出来和大家分享一下
select语句执行顺序
(7)SELECT (8)DISTINCT (10)<TOP_specification> <select_list>
(1)from <left_table>
(3) <join_t ......
经典SQL语句大全
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
......