博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql顶部菜单项消失_SQL选择顶部
阅读量:2531 次
发布时间:2019-05-11

本文共 3828 字,大约阅读时间需要 12 分钟。

sql顶部菜单项消失

SQL选择顶部 (SQL Select Top)

SQL SELECT TOP clause is very useful when dealing with a huge set of data or tables with a huge amount of data.

当处理大量数据或包含大量数据的表时,SQL SELECT TOP子句非常有用。

This clause is used to restrict the number of records to return a result set.

此子句用于限制返回结果集的记录数。

The SELECT TOP clause can be used in two ways.

SELECT TOP子句可以两种方式使用。

  1. By providing the number of records to return as part of the result set.

    通过提供要返回的记录数作为结果集的一部分。
  2. Providing the percentage of the number of records to return as part of the result set.

    提供要返回的记录数的百分比作为结果集的一部分。

We will try to understand both the usage in detail in below-mentioned sections.

我们将在以下各节中尝试详细了解这两种用法。

clause to select a limited number of rows. In Oracle, ROWNUM does the same job. However, it’s supported by SQL Server and all the examples given here will work on SQL Server database. 子句来选择有限数量的行。 在Oracle中,ROWNUM执行相同的工作。 但是,它受到SQL Server的支持,此处给出的所有示例均适用于SQL Server数据库。

SQL选择顶部–要返回的记录数 (SQL Select Top – Number of Records to Return)

We will try to understand the syntax for using SQL SELECT TOP by providing the number of records to return as the result set.

通过提供要返回的记录数作为结果集,我们将尝试了解使用SQL SELECT TOP的语法。

Select Top Syntax

选择顶部语法

SELECT TOP number column_name FROM table_name WHERE condition;

In the syntax above all the columns data is retrieved based on the WHERE clause and restricted by the number that is provided as part of the SELECT TOP.

在以上语法中,所有列数据都是基于WHERE子句检索的,并受作为SELECT TOP一部分提供的数字的限制。

Let’s consider the following Customer Table to understand SELECT TOP command for copying all the columns data based on a condition.

让我们考虑下面的客户表,以了解用于根据条件复制所有列数据的SELECT TOP命令。

Customer:

顾客:

CustomerId CustomerName CustomerAge CustomerGender
1 John 31 M
2 Amit 25 M
3 Annie 35 F
4 Tom 38 M
顾客ID 顾客姓名 客户年龄 客户性别
1个 约翰 31 中号
2 阿米特 25 中号
3 安妮 35 F
4 汤姆 38 中号

Scenario:

场景

Get the first-row data from Customer table where gender is male.

从“客户”表中获取性别为男性的第一行数据。

SELECT TOP 1 * FROM Customer WHERE CustomerGender = 'M';

Output:

输出

CustomerId CustomerName CustomerAge CustomerGender
1 John 31 M
顾客ID 顾客姓名 客户年龄 客户性别
1个 约翰 31 中号
SQL Top Number Records

SQL Top Based on Number of Records

SQL基于记录数的排名

SQL选择要返回的记录的最高百分比 (SQL Select Top Percent Of Records to Return)

We will try to understand the syntax for using SQL SELECT TOP by providing the percentage of records to return as the result set.

通过提供要返回的记录百分比作为结果集,我们将尝试了解使用SQL SELECT TOP的语法。

Syntax:

语法

SELECT TOP number PERCENT column_name FROM table_name WHERE condition;

In the syntax above all the columns data is retrieved based on the WHERE clause and restricted by the percent that is provided as part of the SELECT TOP.

在以上语法中,所有列数据都是基于WHERE子句检索的,并受作为SELECT TOP一部分提供的百分比的限制。

Let’s consider the following Customer Table to understand SELECT INTO command for copying all the columns data based on a condition.

让我们考虑以下客户表,以了解用于根据条件复制所有列数据的SELECT INTO命令。

Scenario:

场景

Get 50% rows data from Customer table where gender is male.

从“客户”表中获取性别为男性的50%行数据。

Query:

查询

SELECT TOP 50 PERCENT * FROM Customer WHERE CustomerGender = 'M';

Output:

输出

CustomerId CustomerName CustomerAge CustomerGender
1 John 31 M
2 Amit 25 M
顾客ID 顾客姓名 客户年龄 客户性别
1个 约翰 31 中号
2 阿米特 25 中号
SQL Top Based on Percent

SQL Top Based on Percent

SQL Top基于百分比

多个SELECT TOP语句 (Multiple SELECT TOP Statements)

We can combine multiple SELECT TOP statements to get the desired result

我们可以组合多个SELECT TOP语句以获得所需的结果

Syntax:

语法

SELECT TOP number column_name FROM table_name WHERE condition (the select statement with another SELECT TOP);

Scenario:

场景

Get the first-row data from Customer table where gender is male.

从“客户”表中获取性别为男性的第一行数据。

Query:

查询

SELECT TOP 1 * FROM Customer WHERE CustomerAge = (SELECT TOP 1 CustomerAge FROM Customer ORDER BY CustomerAge desc);

Output:

输出

CustomerId CustomerName CustomerAge CustomerGender
4 Tom 38 M
顾客ID 顾客姓名 客户年龄 客户性别
4 汤姆 38 中号
SQL Multiple Top

SQL Multiple Top

SQL多顶

翻译自:

sql顶部菜单项消失

转载地址:http://tlmzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_02 微服务核心基础讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-01 什么是微服务的注册中心
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-03CAP原理、常见面试题
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-04 SpringCloud微服务核心组件Eureka介绍和闭源后影响...
查看>>