Table of Contents
原始的表 (用在例子中的):
TOP 子句
SQL Server 的语法:
SQL TOP 实例
结果:
SQL TOP PERCENT 实例
第一种方法:
MySQL 语法
Oracle 语法
oracle中的rownum 只能用以上符号(<、<=、!=)。
例子
Home Database Mysql Tutorial oracle、mysq、sqlserver的区别

oracle、mysq、sqlserver的区别

Jun 07, 2016 pm 03:08 PM
oracle sqlserver the difference

一、oracle、mysq、sqlserver取结果中几行记录的 区别 http://www.w3school.com.cn/sql/sql_top.asp 原始的表 (用在例子中的): Persons 表: Id LastName FirstName Address City 1 Adams John Oxford Street London 2 Bush George Fifth Avenue New York 3

一、oracle、mysq、sqlserver取结果中几行记录的区别

http://www.w3school.com.cn/sql/sql_top.asp

 

原始的表 (用在例子中的):

Persons 表:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing
4 Obama Barack Pennsylvania Avenue Washington

TOP 子句

TOP 子句用于规定要返回的记录的数目。

对于拥有数千条记录的大型表来说,TOP 子句是非常有用的。

注释:并非所有的数据库系统都支持 TOP 子句。

SQL Server 的语法:

SELECT TOP number|percent column_name(s)FROM table_name<p></p><h2 id="SQL-TOP-实例">SQL TOP 实例</h2><p>现在,我们希望从上面的 "Persons" 表中选取头两条记录。</p><p>我们可以使用下面的 SELECT 语句:</p><pre class="brush:php;toolbar:false">SELECT <code>TOP 2</code> * FROM Persons
Copy after login

结果:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York

SQL TOP PERCENT 实例

现在,我们希望从上面的 "Persons" 表中选取 50% 的记录。

我们可以使用下面的 SELECT 语句:

SELECT <code>TOP 50 PERCENT</code> * FROM Persons
Copy after login

结果:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York

第一种方法:

select top n * from  
(select top m * from tablename order by columnname) a 
order by columnname desc 
Copy after login
这个是用一个 sqlserver中 top比order by 后执行 的原理。
Copy after login

第二种方法:

/*以下示例将返回行号为 50 到 60(含)的行,并以 OrderDate 排序。*/ 
select * 
    from(
        select row_number() over (order by orgid) as rownum from org_info
    ) as wo
where wo.rownumber between 50 and 60
Copy after login



MySQL 语法

SELECT column_name(s)FROM table_nameLIMIT number
Copy after login

例子

SELECT *FROM Persons LIMIT 5
Copy after login

Oracle 语法

SELECT column_name(s)FROM table_nameWHERE ROWNUM <= number
Copy after login

SELECT *
  FROM (SELECT ROWNUM RM, UI.* FROM USER_INFO UI WHERE ROWNUM < 10)
 WHERE RM > 5;
Copy after login

oracle中的rownum 只能用以上符号(<、<=、!=)。

这个中也可以用 继续进行限制,如 最后一个where 条件中变为:RM>5 AND RM<8。那结果就是 取 第6到7条记录了!

例子

SELECT *FROM PersonsWHERE ROWNUM <= 5
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
注意 
Copy after login
<span ><strong>1、sqlserver 中SQL的执行顺序。</strong></span>
Copy after login
  1. FROM:对FROM子句中的前两个表执行笛卡尔积(Cartesian product)(交叉联接),生成虚拟表VT1
  2. ON:对VT1应用ON筛选器。只有那些使为真的行才被插入VT2。
  3. OUTER(JOIN):如 果指定了OUTER JOIN(相对于CROSS JOIN 或(INNER JOIN),保留表(preserved table:左外部联接把左表标记为保留表,右外部联接把右表标记为保留表,完全外部联接把两个表都标记为保留表)中未找到匹配的行将作为外部行添加到 VT2,生成VT3.如果FROM子句包含两个以上的表,则对上一个联接生成的结果表和下一个表重复执行步骤1到步骤3,直到处理完所有的表为止。
  4. WHERE:对VT3应用WHERE筛选器。只有使为true的行才被插入VT4.
  5. GROUP BY:按GROUP BY子句中的列列表对VT4中的行分组,生成VT5.
  6. CUBE|ROLLUP:把超组(Suppergroups)插入VT5,生成VT6.
  7. HAVING:对VT6应用HAVING筛选器。只有使为true的组才会被插入VT7.
  8. SELECT:处理SELECT列表,产生VT8.
  9. DISTINCT:将重复的行从VT8中移除,产生VT9.
  10. ORDER BY:将VT9中的行按ORDER BY 子句中的列列表排序,生成游标(VC10).
  11. TOP:从VC10的开始处选择指定数量或比例的行,生成表VT11,并返回调用者。

注意:这里的TOP 在 order by 的后面执行。意思是:sqlserver先进行排序再取top的数据。

2、oracle 中 order by 也是比 rownum先执行。


二、IF ELSE 区别


mysql和oracle的区别

1)、注意elseif区别

在mysql中:

<span>IF <em>search_condition</em> THEN <em>statement_list</em></span>
Copy after login
<span><span>    </span>[ELSEIF <em>search_condition</em> THEN <em>statement_list</em>] ...</span>
Copy after login
<span><span>    </span>[ELSE <em>statement_list</em>]</span>
Copy after login
<span>END IF</span>
Copy after login
2)、在oracle中:

IF 条件1 THEN

...如果条件1为真,则执行这里的语句...

ELSIF 条件2 THEN

...如果条件1为假,但是条件2为真,则执行这里的语句...

ELSE

...如果条件1和条件2都为假,则执行这里的语句...

END IF;











 
Copy after login
Copy after login
Copy after login
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
Difference between centos and ubuntu Difference between centos and ubuntu Apr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

The difference between laravel and thinkphp The difference between laravel and thinkphp Apr 18, 2025 pm 01:09 PM

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

How to view firewall status in centos How to view firewall status in centos Apr 14, 2025 pm 08:18 PM

The state of the CentOS firewall can be viewed through the sudo firewall-cmd --state command, returning to running or not running. For more detailed information, you can use sudo firewall-cmd --list-all to view, including configured areas, services, ports, etc. If firewall-cmd does not solve the problem, you can use sudo iptables -L -n to view iptables rules. Be sure to make a backup before modifying the firewall configuration to ensure server security.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

See all articles