select * from * where * group by * having * order by * computer by *

解决方案 »

  1.   

    Specifies the columns to be returned by the query.
    SyntaxSELECT [ 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]
    ArgumentsALLSpecifies that duplicate rows can appear in the result set. ALL is the default.DISTINCTSpecifies that only unique rows can appear in the result set. Null values are considered equal for the purposes of the DISTINCT keyword.TOP n [PERCENT]Specifies that only the first n rows are to be output from the query result set. If PERCENT is also specified, only the first n percent of the rows are output from the result set. When specified with PERCENT, n must be an integer between 0 and 100.
    If the query includes an ORDER BY clause, the first n rows (or n percent of rows) ordered by the ORDER BY clause are output. If the query has no ORDER BY clause, the order of the rows is arbitrary.WITH TIESSpecifies that additional rows be returned from the base result set with the same value in the ORDER BY columns appearing as the last of the TOP n (PERCENT) rows. TOP ...WITH TIES can only be specified if an ORDER BY clause is specified.<select_list>The columns to be selected for the result set. The select list is a series of expressions separated by commas. *Specifies that all columns from all tables and views in the FROM clause should be returned. The columns are returned by table or view, as specified in the FROM clause, and in the order in which they exist in the table or view. table_name | view_name | table_alias.*Limits the scope of the * to the specified table or view. column_nameIs the name of a column to return. Qualify column_name to prevent an ambiguous reference, such as occurs when two tables in the FROM clause have columns with duplicate names. For example, the Customers and Orders tables in the Northwind database both have a column named ColumnID. If the two tables are joined in a query, the customer ID can be specified in the select list as Customers.CustomerID.expressionIs a column name, constant, function, any combination of column names, constants, and functions connected by an operator(s), or a subquery. IDENTITYCOLReturns the identity column. For more information, see IDENTITY (Property), ALTER TABLE, and CREATE TABLE. 
    If the more than one table in the FROM clause has a column with the IDENTITY property, IDENTITYCOL must be qualified with the specific table name, such as T1.IDENTITYCOL.ROWGUIDCOLReturns the row global unique identifier column. 
    If the more than one table in the FROM clause with the ROWGUIDCOL property, ROWGUIDCOL must be qualified with the specific table name, such as T1.ROWGUIDCOL.column_aliasIs an alternative name to replace the column name in the query result set. For example, an alias such as 換uantity? or 換uantity to Date? or 換ty?can be specified for a column named quantity. 
    Aliases are used also to specify names for the results of expressions, for example:USE NorthwindSELECT AVG(UnitPrice) AS 'Average Price'
    FROM [Order Details]column_alias can be used in an ORDER BY clause; however, it cannot be used in a WHERE, GROUP BY, or HAVING clause. If the query expression is part of a DECLARE CURSOR statement, column_alias cannot be used in the FOR UPDATE clause. 
      

  2.   

    Retrieves rows from the database and allows the selection of one or many rows or columns from one or many tables. The full syntax of the SELECT statement is complex, but the main clauses can be summarized as:SELECT select_list
    [INTO new_table_]
    FROM table_source
    [WHERE search_condition]
    [GROUP BY group_by_expression]
    [HAVING search_condition]
    [ORDER BY order_expression [ASC | DESC] ]The UNION operator can be used between queries to combine their results into a single result set. SyntaxSELECT statement ::=
    <query_expression>
    [ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }
    [,...n] ]
    [ COMPUTE 
    { { AVG | COUNT | MAX | MIN | SUM } (expression) } [,...n] 
    [ BY expression [,...n] ]
    ]
    [ FOR BROWSE ]
    [ OPTION (<query_hint> [,...n]) ]<query expression> ::=
    { <query specification> | (<query expression>) }
    [UNION [ALL] <query specification | (<query expression>) [...n] ]<query specification> ::= 
    SELECT [ ALL | DISTINCT ]
    [ {TOP integer | TOP integer PERCENT} [ WITH TIES] ] 
    <select_list>
    [ INTO new_table ]
    [ FROM {<table_source>} [,...n] ]
    [ WHERE <search_condition> ]
    [ GROUP BY [ALL] group_by_expression [,...n] 
    [ WITH { CUBE | ROLLUP } ]
    ]
    [ HAVING <search_condition> ]
     
      

  3.   

    从数据库中检索行,并允许从一个或多个表中选择一个或多个行或列。虽然 SELECT 语句的完整语法较复杂,但是其主要的子句可归纳如下:SELECT select_list
    [ INTO new_table ] 
    FROM table_source 
    [ WHERE search_condition ] 
    [ GROUP BY group_by_expression ] 
    [ HAVING search_condition ] 
    [ ORDER BY order_expression [ ASC | DESC ] ] 可以在查询之间使用 UNION 运算符,以将查询的结果组合成单个结果集。语法
    SELECT statement ::=
        < query_expression >
        [ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }
            [ ,...n ]    ] 
        [ COMPUTE
            { { AVG | COUNT | MAX | MIN | SUM } ( expression ) } [ ,...n ]
            [ BY expression [ ,...n ] ]
        ] 
        [ FOR { BROWSE | XML { RAW | AUTO | EXPLICIT }
                [ , XMLDATA ]
                [ , ELEMENTS ]
                [ , BINARY base64 ]
            } 

        [ OPTION ( < query_hint > [ ,...n ]) ] < query expression > ::=
        { < query specification > | ( < query expression > ) }
        [ UNION [ ALL ] < query specification | ( < query expression > ) [...n ] ]< query specification > ::=
        SELECT [ ALL | DISTINCT ]
            [ { TOP integer | TOP integer PERCENT } [ WITH TIES ] ]
            < select_list >
        [ INTO new_table ]
        [ FROM { < table_source > } [ ,...n ] ]
        [ WHERE < search_condition > ]
        [ GROUP BY [ ALL ] group_by_expression [ ,...n ]
            [ WITH { CUBE | ROLLUP } ]
        ]
        [HAVING <search_condition>]由于 SELECT 语句的复杂性,下面按子句说明详细的语法元素和参数:
    创建新表并将结果行从查询插入新表中。用户若要执行带 INTO 子句的 SELECT 语句,必须在目的数据库内具有 CREATE TABLE 权限。SELECT...INTO 不能与 COMPUTE 子句一起使用。有关更多信息,请参见事务和显式事务。 通过在 WHERE 子句中包含 FALSE 条件,可以使用 SELECT...INTO 创建没有数据的相同表定义(不同表名)。语法
    [ INTO new_table ]参数
    new_table根据选择列表中的列和 WHERE 子句选择的行,指定要创建的新表名。new_table 的格式通过对选择列表中的表达式进行取值来确定。new_table 中的列按选择列表指定的顺序创建。new_table 中的每列有与选择列表中的相应表达式相同的名称、数据类型和值。当选择列表中包含计算列时,新表中的相应列不是计算列。新列中的值是在执行 SELECT...INTO 时计算出的。在此次发布的 SQL Server 版本中,select into/bulkcopy 数据库选项对是否可以使用 SELECT INTO 创建永久表没有影响。对包括 SELECT INTO 在内的某些大容量操作的记录量,取决于对数据库有效的恢复模式。有关更多信息,请参见使用恢复模型。在以前发布的版本中,如果设置了 select into/bulk copy,则可用 SELECT INTO 创建永久表。select into/bulk copy 用于向后兼容,但在以后的版本中可能不支持该选项。有关更多信息,请参考"恢复模式"和"向后兼容性"主题以及 ALTER DATABASE 主题。