Advanced Query of Computer Tertiary Database

1. There is a book list (book number, book title, publication date, unit price) in the SOLServer 208 database, where "book number is the main code. The first three books with the highest unit price in the January 2015 edition are to be checked. The details of the query. Which of the following query statements can correctly complete the information query requirements is

A、SELECT TOP 3 * FROM 图书表
WHERE 出版日期 BETWEEN #2015/1/1# AND #2015/1/31# ORDER BY 单价 DESC
B、SELECT TOP 3 * FROM 图书表
WHERE 出版日期 BETWEEN '2015/1/1’ AND ’2015/1/31' ORDER BY 单价 DESC
C、SELECT* TOP 3 FROM 图书表
WHERE 出版目期 BETWEEN2015/1/1AND2015/1/31'ORDER BY单价DESC
D、SELECT* TOP 3 FROM 图书表
WHERE 出版日期 BETWEEN #2015/1/1# AND #2015/1/31# ORDER BY单价DESC

The reference answer is B

Analysis: The syntax format of C and D is incorrect, TOP 3 should be placed before *, and the date format of option A is incorrect. So the answer is B.

2. There is a commodity table (commodity number, commodity name, category, unit price) and a sales table (commodity number, sales time, sales quantity) in a database of SNSerer 203. Now I want to check the commodity names and unit prices of mobile phone products that have not been sold in September 2005. Which of the following query statements can correctly complete the query requirements is

A、SELECT 商品名,单价 FROM 商品表
WHERE 商品号 IN(
	SELECT 商品号 FROM 销售表
	WHERE 销售时间 BETWEEN '2015/9/1' AND '2015/9/30' 
	AND 类别!='手机')
AND 类别='手机'
B、SELECT 商品名,单价 FROM 商品表
JOIN 销售表 ON 商品表.商品号=销售表.商品号
WHERE 销售时间 NOT BETWEEN2015/9/1AND '2015/9/30' 
AND 类别='手机'
C、SELECT 商品名,单价 FROM 商品表 
WHERE 商品号 NOT IN (
	SELECT 商品号 FROM 销售表
	WHERE 销售时间 BETWEEN '2015/9/1’ AND ’2015/9/30' 
	AND 类别='手机')
AND 类别 ='手机'
D、SELECT 商品名,单价 FROM 商品表
JOIN 销售表 ON 商品表.商品号=销售表.商品号 
WHERE 销售时间 BETWEEN '2015/9/1' 
AND '2015/9/30' AND 类别 !='手机'

The reference answer is C

Parsing: When using a subquery for set-based testing, the operator IN and NOT IN are used to compare the value of an expression with the result set returned by the subquery. Its form is:
WHERE expression [NOT] IN (subquery)
The subquery statement in this form is implemented in steps, that is, the subquery is executed first, and then the outer query is executed based on the result of the subquery. The sub-query in this question queries the mobile phones sold in September 2015, and then queries the product names and unit prices that do not belong to this range. So the answer is C.

3. There is no car table (car model, car name, color, price>, where "car model" is the main code. Now we want to query the names, colors and prices of all white and black cars. The query can be completed correctly in the following statement yes

A、SELECT 汽车名称,颜色,价格 FROM 汽车表
WHERE 颜色='白色' OR 颜色='黑色'
B、SELECT 汽车名称,颜色,价格 FROM汽车表
WHERE 颜色='白色' AND 颜色='黑色'
C、SELECT 汽车名称,颜色,价格FROM汽车表
WHERE 颜色 LIKE '[白色黑色]'
D、SELECT 汽车名称,颜色,价格FROM汽车表
WHERE 颜色 LIKE '[白色,黑色]'

The reference answer is A

Analysis: The like keyword is mainly for character fields, and its function is to retrieve the corresponding substring in a character field column. Options C and D are wrong. Only when the conditions on both sides of the And keyword are satisfied will the query result. The function of option B is to query the color of the car, which is white and black at the same time. There is no such car. So the answer is A.

4. There is no car sales table (car model, sales time, sales price. Sales quantity", where (car model, sales time> is the main code. Now we want to check the car model and total sales volume of the car with the largest total sales in the past 215 years. Quantity (including ties). Which of the following statements can correctly complete the query is

A、SELECT TOP 1 WITH TIES 汽车型号,SUM(汽车型号) FROM 汽车销售表 
WHERE 销售时间 BETWEEN '2015/1/1' AND '2015/12/31'
GROUP BY 汽车型号
ORDER BY SUM(汽车型号)DESC
B、SELECT TOP 1 WITH TIES 汽车型号,SUM(销售数量) FROM 汽车销售表 
WHERE 销售时间 BETWEEN '2015/1/1' AND '2015/12/31'
GROUP BY 汽车型号
ORDER BY SUM(销售数量)ASC
C、SELECT TOP 1 WITH TIES 汽车型号,SUM(销售数量) FROM 汽车销售表
WHERE销售时间 BETWEEN '2015/1/1' AND '2015/12/31'
GROUP BY 汽车型号
ORDER BY SUM(销售数量) DESC
D、SELECT TOP 1 WITH TIES 汽车型号,SUM(汽车型号) FROM
汽车销售表 WHERE 销售时间 BETWEEN '2015/1/1' AND '2015/12/31'
GROUP BY 汽车型号
ORDER BY SUM(汽车型号) ASC

The reference answer is C

Analysis: This question uses the TOP predicate to limit the output results, DESC means descending order, ASC means ascending order, the question requires to query the car with the most total sales, so the first record in descending order should be queried, so the option BD is wrong.
Option A is sorted by car model, and those that do not meet the requirements of the question are sorted by the total number of sales, so the answer is C.

5. There is an employee table (employee number, name, salary, department", where "employee number" is the main code. Now we want to query the name and salary of the employee with the lowest salary in the "Basic Department". The query can be completed correctly in the following statement What is required is

A、SELECT 姓名,工资 FROM 员工表
WHERE 工资 INSELECT MIN(工资、FROM 员工表 
	WHERE 所在部门='基础部') 
AND 所在部门='基础部'
B、SELECT 姓名,工资 FROM 员工表
WHERE工资INSELECT MIN(工资、FROM 员工表 
	WHERE所在部门='基础部')
C、SELECT 姓名,工资 FROM 员工表 
WHERE工资IN(
	SELECT MAX(工资、FROM 员工表 
	WHERE 所在部门='基础部')
AND 所在部门='基础部'
D、SELECT 姓名,工资 FROM 员工表
WHERE工资IN(
	SELECT MAX(工资、FROM 员工表 
	WHERE所在部门='基础部')

The reference answer is A

Analysis: The question asked to query the employees with the lowest salary should use the MIN function, so the option CD is wrong.
After executing the subquery in option B, the outer query lacks the statement to judge the department as the base department.
So the answer is A.

6. There is a teacher table (teacher number, teacher name, title, gender), where "teacher number" is the primary key. Now to query the number of female teachers with the title of "Professor", which of the following statements can correctly complete the query is

A、SELECT COUNT(*) FROM 教师表 WHERE 职称='教授' and 性别='女'
B、SELECT SUM(职称) FROM 教师表 WHERE职称='教授' or 性别='女'
C、SELECT COUNT(职称) FROM教师表WHERE职称='教授' or 性别='女'
D、SELECT SUM(*) FROM 教师表 WHERE 职称='教授' and 性别='女'

The reference answer is A

Analysis: The knowledge points examined in this question are: data query
B and D are summation, and the number of people required in the question should be counted, so B and D are wrong.
The condition of C is that the title is a professor or the gender is female. The question requires a female professor, and should be used, so C is wrong, so the answer is A.

7. There is a statement that defines a trigger in SQL Server as follows:
CREATE TRIGGER tri_1
ON T1 FOR UPDATE
AS...
The following statement about the function of the trigger is correct.
A. A table is defined on the T1 table that is triggered by a data change operation. The pre-trigger trigger
B. A post-trigger trigger is defined on the T1 table, which is triggered by data addition, deletion, and modification operations.
C. A post-trigger trigger is defined on the T1 table, which is triggered by a data modification operation.
D. A pre-triggered trigger triggered by data addition, deletion, and modification operations is defined on the T1 table. The
reference answer is C

Analysis: The trigger defined with the FOR or AFTER option is a post-trigger trigger, that is, the trigger is executed only after the operations in the statement that caused the trigger to be executed have been successfully executed, and all constraint checks have been successfully completed. . Triggers defined using the INSTEAD OF option are pre-triggered triggers. In this mode of triggers, the trigger is specified to execute instead of executing the SQL statement that caused the trigger to execute, thereby replacing the triggered action.
The operation specified in the statement is update, the update operation.

8. The following statements about SQL Server indexes are correct:
A. A clustered index can only be established on one column
B. The only index cannot be a clustered index
C. If a primary key is defined on a table without a clustered index, the system will automatically add a primary key to it. Create a clustered index on
D. You cannot create multiple unique indexes on a table. The
reference answer is C

Analysis: The simplified syntax for creating an index is:
CREATE [UNIQUE][CLUSTERED|NONCLUSTERED] INDEX index_name
ON (column [ASC|DESC][,…n])
column: One or more columns on which the index is based. If multiple column names are specified, a composite index is created for the composite values ​​of the specified columns.
AB errors are known from the grammar.
Unique indexes ensure that indexed columns do not contain duplicate values. In the case of a multi-column unique index, it is guaranteed that each combination of values ​​in the indexed column is unique (D wrong).

9. In SQL Server, there is the following statement to create a partition function:
CREATE PARTITION FUNCTION PFl(int)
AS RANGE LEFT FOR VALUES (100,200)
The function of this statement is
A, creates a partition, and the interval is: [100,200]
B. Created 2 partitions, the intervals are: <=100, >=200
C. Created 3 partitions, the intervals are: <=100, [101,200], >200
D. Created 3 partitions, the interval They are: <100, [100,200],>200
The reference answer is C

Analysis: The sql statement to create a partition function is:
CREATE PARTITION FUNCTION partition_function_name(input_parameter_type)
AS RANGE [LEFT|RIGHT]
FOR VALUES([boundary_value[,…n]])
[;]
It can be seen from the grammar that the boundary values ​​of the partitions in this question are respectively is 100 and 200, then it will be divided into 3 intervals, namely <=100, >=101 and <=200, >200.

10. There is a house table (house number, area, monthly rent), where "house number" is the primary key. Now I want to check the house number and monthly rent with the cheapest monthly rent among houses with an area of ​​10-120 square meters. Which of the following statements correctly completes the query requirement is

A、SELECT TOP 1 WITH TIES 房屋号,月租金 FROM 房屋表
WHERE 面积 BETWEEN 100 AND 120
ORDER BY 月租金 DESC
B、SELECT 房屋号,月租金 FROM 房屋表
WHERE 月租金=MIN(月租金) AND 面积 BETWEEN 100 AND 120
C、SELECT TOP 1 WITH TIES 房屋号,月租金 FROM 房屋表
WHERE 面积 BETWEEN 100 AND 120
ORDER BY 月租金 ASC
D、SELECT 房屋号,月租金 FROM 房屋表
WHERE 面积 BETWEEN 100 AND 120
AND 月租金 IN (SELECT MIN(月租金) FROM 房屋表)

The reference answer is C

Analysis: According to the meaning of the question, this question examines the cheapest monthly rent, so it should sort the monthly rent in ascending order, take top 1, and the limited condition is that the area is between 100-120 square meters.
Option A is descending order, wrong.
Option B, aggregate function min should appear in having, or in subquery, wrong.
Option D, the subquery will return the minimum value of all rents, which does not match the condition between 100 and 120 of the parent query, resulting in an empty search result.
So the answer is C.

11. There is a book table (book number, title, price, publication date", where the book number is the main code and the publication date is the tcate type. Now you want to query the titles and prices of all books published in 2018. The following statements can be correct What is required to complete the query is
A, SELECT book title, price FROM book table
WHERE publication date BETWEEN 2018-01-01 AND 2018-12-31
B, SELECT book title, price FROM book table
WHERE publication date=2018
C, SELECT book name, price FROM book table
WHERE publication date = '2018'
D, SELECT book title, price FROM book table
WHERE publication date BETWEEN '2018-01-01' AND '2018-12-31'
reference answer is D

Analysis: In the SQL language, date data needs to be enclosed in English single quotation marks. If you need to refer to the year separately, you need to call the year function year( ) for the date data to calculate.
Therefore, the answer to this question is D.

12. There is a sales table (book number, sales date, sales quantity) in a certain SULServer 200S database, and the main code is (book number, sales date). Now we want to query the total sales quantity of the book with the most accumulated sales quantity. The following statements can correctly complete the query requirements are
A, SELECT MAX (sales quantity) FROM sales table
ORDER BY sales quantity DESC
B, SELECT TOP 1 COUNT (sales quantity) FROM sales table
GROUP BY book
number ORDER BY COUNT (sales quantity) DESC
C, SELECT TOP 1 SUM (sales quantity) FROM sales table
GROUP BY book
number ORDER BY SUM (sales quantity) DESC
D, SELECT MAX (sales quantity) FROM sales table
GROUP BY book number The
reference answer is C

Analysis: Accumulate the number of sales, you need to use the sum function. At most, you need to use the order by phrase desc to sort in descending order, and limit the result set with top 1.

13. There is an employee table (employee number, name, age, department), where "employee number" is the main code. Now we want to query the department with the largest number of people in the department. In the following statement, what can correctly complete the query is
A, SELECT TOP 1 WITH TIES department FROM employee table
GROUP BY department
ORDER BY COUNT(*)DESC
B, SELECT TOP 1 department FROM employee table
GROUP BY department
ORDER BY SUM (employee number) DESC
C, SELECT MAX (employee number) FROM employee table
GROUP BY department
D, SELECT MAX (employee number) FROM employee table
ORDER BY department
The reference answer is A

Analysis: Options C and D can be determined without considering the group by and order by phrases, and the employee with the largest employee number is displayed instead of the department number required by the title.
Option A not only considers the existence of "the most ties", but also in descending order by the number of records, there is no problem.
So the answer to this question is A.

14. There is a house table (house number, address, number of rooms, monthly rent), where "house number" is the main code. Now I want to query the house numbers and monthly rents of the 3 houses with the lowest monthly rent among the 2-bedrooms. The following statements can correctly complete the query requirements are
A, SELECT TOP3 house number, monthly rent FROM house table
WHERE number of rooms = 2
ORDER BY monthly rent ASC
B, SELECT TOP3 house number, monthly rent FROM house table
WHERE number of rooms = 2
ORDER BY monthly rent DESC
C, SELECT TOP 3 house number, monthly rent FROM house table
WHERE room number = 2
ORDER BY room number ASC
D, SELECT TOP 3 house number, monthly rent FROM house table
WHERE room number = 2
ORDER BY room number DESC
reference answer is A

Analysis: The specific operation can be analyzed through the title description. The retrieval condition is "2-bedroom", and then the monthly rent is sorted in ascending order, and the first 3 records are taken.

Guess you like

Origin blog.csdn.net/Redamancy06/article/details/127030562