WEB开发网
开发学院数据库MSSQL Server SQL Server 2000中的SQL语言 阅读

SQL Server 2000中的SQL语言

 2008-12-04 10:12:05 来源:WEB开发网   
核心提示: COMPUTE BY子句用于增加各列汇总行,SELECT子句的语法形式如下所示:SELECT [ ALL | DISTINCT ][ TOP n [ PERCENT ] [ WITH TIES ] ]< select_list >< select_list > ::

COMPUTE BY子句用于增加各列汇总行。

SELECT子句的语法形式如下所示:

SELECT [ ALL | DISTINCT ]  [ TOP n [ PERCENT ] [ WITH TIES ] ] < select_list >
< select_list > ::=
{  *    | { table_name | view_name | table_alias }.*   |   { column_name | expression | IDENTITYCOL | ROWGUIDCOL }      [ [ AS ] column_alias ]   | column_alias = expression  }  [ ,...n ]

显示居住在加利福尼亚州且姓名不为 McBadden 的作者列。USE pubs
SELECT au_fname, au_lname, phone AS Telephone
FROM authors
WHERE state = 'CA' and au_lname <> 'McBadden'
ORDER BY au_lname ASC, au_fname ASC

使用两个相关子查询查找作者姓名,这些作者至少参与过一本受欢迎的计算机书籍的创作。

USE pubs
SELECT au_lname, au_fname
FROM authors
WHERE au_id IN
  (SELECT au_id
  FROM titleauthor
  WHERE title_id IN
  (SELECT title_id
  FROM titles
WHERE type = 'popular_comp'))

显示含有本年度截止到现在的当前销售额的行,然后按type以递减顺序计算书籍的平均价格和预付款总额

USE pubs
SELECT CAST(title AS char(20)) AS title, type, price, advance
FROM titles
WHERE ytd_sales IS NOT NULL
ORDER BY type DESC
COMPUTE AVG(price), SUM(advance) BY type
COMPUTE SUM(price), SUM(advance)

先删除表T1,然后又创建一个带有四个列的表T1。最后利用INSERT 语句插入一些数据行,这些行只有部分列包含值。

上一页  1 2 3 4 5 6 7 8  下一页

Tags:SQL Server SQL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接