Computer three-level database review 4-advanced data query

Future Education Chapter VI Topic Notes_Advanced Data Query

1. If a user wants to access a database table in SQL server, he must establish a connection with the table to indicate a communication channel. When the connection is interrupted, it cannot be accessed.
2. The top three types of product sentences with the most quantity: select top 3 with ties
5. Case when sentences:
case sex case
When '1' THEN'Male' When Grade between 90 and 100 Then'Excellent'
When '2' THEN'Female '```
ELSE'Others' Else'Failed '
END END
6, top3 can only query the first 3 rows of data, regardless of whether there are repetitions, only the first 3 rows of records can be selected mechanically.
7. Support user-defined functions in SQL server2008: scalar functions, embedded table-valued functions and multi-statement table-valued functions. Scalar functions can appear in the target column of the select statement, and the other two functions must be placed in the from clause of the select statement.
11. The usage of the set operators IN, EXCEPT, INTERSECT, UNION in SQL are as follows:
① IN, to determine whether the given value matches the value in the subquery or the list, and select the row that matches any value in the list.
②EXCEPT, refers to the data that exists in the first set, but does not exist in the second set
③INTERSECT, refers to the data that exists in both sets
④UNION, the operator is used to merge two or more select statements Result set (note that the select statement within UNION must have the same number of columns with similar data types, and the order must be the same)
12. Range division is obviously beneficial to range query and point query. S contains less data and is suitable for S Copy method.
13. For tables that often need to perform query operations and have a large amount of data, and attributes that often appear in the where clause, order by clause, group by clause, you can consider using indexes.
17. Window function formula: function name (column) OVER (option). The OVER keyword means to treat the function as a windowing function instead of an aggregate function. In SQLserver 2005/2008, two types are supported: ranking window function and aggregate window function. Aggregate windowing function can only use PARTITION BY clause or without any clause, ORDER BY cannot be used with aggregate windowing function. Many aggregate windowing functions can be used for the operation of window functions, such as SUM, AVG, etc.
18. Using the case function in the query statement can achieve the purpose of displaying different types of data in different situations.
20. When using TOP to limit the result set, WITH TIES means the parallel result including the last row of values; TOP n means the first n rows of data of the query result; TOP n percent means the first n% of the data of the query result is taken.
21. Common table expressions can assign a temporarily named name to the result set generated by the query statement. These named result sets are called common table expressions. The syntax format is:
WITH common table expression identifier (list 1...list n) AS (Select statement)
22, COUNT ( ) is the number of statistical tuples, including NULL rows and repeated rows, and COUNT (column name ) Is a way to count the number of values ​​in a column, excluding NULL rows. Since the category of the product may be empty, you need to use COUNT( ) when summarizing.
23. The return value of the scalar function can be all data types except the timestamp type.
28. When using the SELECT statement to query data, the results are stored in memory. If you want to save the query results permanently, such as in a table, you can use the INTO clause in the SELECT statement. The syntax format is: SELECT query list sequence INTO <new table name> FROM data source
31, SET statement is not applicable to scalar function
34, in T-SQL, the operator for the difference operation of query results is EXCEPT.
40. The SELECT INTO statement means selecting data from one table and then inserting the data into another table. This statement structure is usually used to create a backup of a table or to archive records. The statement requires that the target table does not exist when used, because it will be automatically created when inserting.
41. WHERE [NOT] EXISTS (sub-query) sub-query
with EXISTS predicate does not return the result of the query, but only produces logical true values ​​and logical false values
. The meaning of EXISTS is: when there is data that meets the conditions in the sub-query, EXISTS returns True value, otherwise it returns false value.
The meaning of NOT EXISTS is: when there is data that meets the conditions in the subquery, NOT EXISTS returns a false value, otherwise it is true.
WHERE [sth] NOT IN (subquery): It means to judge that the user is not in a certain set.
46. ​​There are the following four functions in SQL 2005:
①ROW_NUMBER: Generate a serial number for each row of records in the query
select row_number() over(order by ** ) as row_number, from table
②RANK: Taking into account the sorting field in the over clause When the value is the same.
③DENSE_RANK: The function of the function is similar to the RANK function, except that it is continuous when generating the sequence number, and the sequence number generated by the RANK function may not be continuous.
④NTILE: can group sequence numbers.
49. In the like clause, there are the following special characters:
①Underscore_: can match any character
②Percent sign%: can match 0 to more characters
③Square brackets []: used to escape (actually only the left side Brackets are used for escaping, and the right square bracket uses the nearest-first principle to match the nearest left square bracket)
④ Pointer ^: used to exclude some characters for matching
63, the grammatical format of using TOP predicate is:
①TOP n: Take the front of the query n rows of data;
②TOP n percent: take the first n% rows of the query result.
③WITH TIES: Indicates that the
TOP predicate is written after the SELECT word (if there is DISTINCT, then TOP is written after DISTINCT)

mind Mapping

Insert picture description here

Guess you like

Origin blog.csdn.net/TOPic666/article/details/115018335