《SQL必知必会》(第3版)SQL是目前使用最为广泛的数据库语言之一。本书没有涉及理论,而是从实践出发,由浅入深地讲解了广大读者所必需的SQL知识,适用于各种主流数据库。实例丰富,便于查阅。本书涉及不同平台上数据的排序、过滤和分组,以及表、视图、联结、子查询、游标、存储过程和触发器等内容,通过本书读者可以系统地学习到SQL的知识和方法。
SELECT XXX FROM XXX;
SELECT XXX,XXX FROM XXX;
SELECT * FROM XXX;
SELECT DISTINCT XXX FROM XXX;
SELECT TOP ? XXX FROM XXX;
-- XXX
# XXX
/* XXX */
SELECT XXX FROM XXX ORDER BY XXX;
SELECT XXX, XXX FROM XXX ORDER BY XXX, XXX;
SELECT XXX, XXX FROM XXX ORDER BY ?, ?;
SELECT XXX, XXX FROM XXX ORDER BY XXX DESC;
SELECT XXX, XXX FROM XXX ORDER BY XXX DESC, XXX;
SELECT XXX, XXX FROM XXX WHERE XXX =?;
SELECT XXX, XXX FROM XXX WHERE XXX < ?;
SELECT XXX, XXX FROM XXX WHERE XXX <> '?';
SELECT XXX, XXX FROM XXX WHERE XXX != '?';
SELECT XXX, XXX FROM XXX WHERE XXX BETWEEN ? AND ?;
SELECT XXX FROM XXX WHERE XXX IS NULL;
SELECT XXX, XXX FROM XXX WHERE XXX = '?' AND XXX <= ?;
SELECT XXX, XXX FROM XXX WHERE XXX = '?' OR XXX = '?';
SELECT XXX, XXX FROM XXX WHERE XXX = '?' OR XXX = '?' AND XXX >= ?;
SELECT XXX, XXX FROM XXX WHERE XXX IN ('?','?') ORDER BY XXX;
SELECT XXX FROM XXX WHERE NOT XXX = '?' ORDER BY XXX;
SELECT XXX FROM XXX WHERE XXX <> '?' ORDER BY XXX;
SELECT XXX, XXX FROM XXX WHERE XXX LIKE 'XXX%'; --开头
SELECT XXX, XXX FROM XXX WHERE XXX LIKE '%XXX%'; --包含
SELECT XXX, XXX FROM XXX WHERE XXX LIKE '%XXX'; --结尾
SELECT XXX FROM XXX WHERE XXX LIKE 'XXX%XXX'; --以XXX起头、以XXX结尾
#%代表搜索模式中给定位置的 0 个、1 个或多个字符
SELECT XXX, XXX FROM XX WHERE XXX LIKE '__ inch teddy bear'; --两个
#下划线(_)只匹配单个字符,而不是多个字符
SELECT XXX FROM XXX WHERE XXX LIKE '[XXX]%' ORDER BY XXX;
#找出所有名字以XXX起头的XXX
SELECT XXX FROM XXX WHERE XXX LIKE '[^XXX]%' ORDER BY XXX;
#查询匹配以XXX之外的任意字符起头的XXX; 前缀字符^(脱字号)来否定, 简化语法
SELECT XXX FROM XXX WHERE NOT XXX LIKE '[XXX]%' ORDER BY XXX;
#使用 NOT 操作符得出类似的结果
#方括号([])用来指定一个字符集,它必须匹配指定位置(通配符的位置)的一个字符
#拼接(concatenate) 将值联结到一起(将一个值附加到另一个值)构成单个值。
SELECT XXX + '(' + XXX + ')' FROM XXX ORDER BY XXX;
SELECT XXX || '(' || XXX || ')' FROM XXX ORDER BY XXX;
SELECT Concat(XXX, ' (', XXX, ')') FROM XXX ORDER BY XXX; --MySQL