、from子句组装来自不同数据源的数据;
2、where子句基于指定的条件对记录行进行筛选;
3、group by子句将数据划分为多个分组;
4、使用聚集函数进行计算;
5、使用having子句筛选分组;
6、计算所有的表达式;
7、使用order by对结果集进行排序。
举例说明: 在学生成绩表中 (暂记为 tb_Grade), 把 "考生姓名"内容不为空的记录按照 "考生姓名" 分组, 并且筛选分组结果, 选出 "总成绩" 大于 600 分的.
标准顺序的 SQL 语句为:
Select 考生姓名, max(总成绩) as max总成绩
from tb_Grade
where 考生姓名 is not null
group by 考生姓名
having max(总成绩) > 600
order by max总成绩
在上面的示例中 SQL 语句的执行顺序如下:
(1). 首先执行 FROM 子句, 从 tb_Grade 表组装数据源的数据
(2). 执行 WHERE 子句, 筛选 tb_Grade 表中所有数据不为 NULL 的数据
(3). 执行 GROUP BY 子句, 把 tb_Grade 表按 "学生姓名" 列进行分组
(4). 计算 max() 聚集函数, 按 "总成绩" 求出总成绩中最大的一些数值
(5). 执行 HAVING 子句, 筛选课程的总成绩大于 600 分的.
(7). 执行 ORDER BY 子句, 把最后的结果按 "Max 成绩" 进行排序.
1 # !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 # <html xmlns="http://www.w3.org/1999/xhtml">
3 # <head>
4 # <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
5 # <style>
6 # #menu ul li{display:inline;}
7 # .on {color:red;}
8 # .off {color:blue;}
9 # #list_new2{display:none;}
10 # </style>
11 # <script src="http://www.google.com/jsapi"></script>
12 # <script>google.load("jquery", "1");</script>
13 # </head>
14 # <body>
15 #
16 #
17 # <div id="menu">
18 # <ul><li id="new1" class="on">标签1</li> <li id="new2" class="off">标签2</li></ul>
19 # </div>
20 #
21 # <div id="list_new1">
22 # <ul>
23 # <li>标签1</li>
24 # <li>标签1</li>
25 # </ul>
26 # </div>
27 # <div id="list_new2">
28 # <ul>
29 # <li>标签2</li>
30 # <li>标签2</li>
31 # </ul>
32 # </div>
33 #
34 #
35 # <script type="text/javascript">
36 # <!--
37 # $("#menu li").click(function()
38 # {
39 # $("#menu li").each(function()
40 # {
41 # $(this).removeClass("on");
42 # $(this).addClass("off");
43 # $("#list_"+$(this).attr("id")).hide();
44 # });
45 # $(this).removeClass("off");
46 # $(this).addClass("on");
47 # $("#list_"+$(this).attr("id")).show();
48 # }
49 # );
50 # //-->
51 # </script>
52 # </body>
53 # </html>
http://www.zhaophp.com/CssDesigner/