>(大于)(Transact-SQL)> (Greater Than) (Transact-SQL)

适用于: 是SQL Server 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 是并行数据仓库 APPLIES TO: YesSQL Server YesAzure SQL Database YesAzure Synapse Analytics (SQL DW) YesParallel Data Warehouse

比较 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 中的两个表达式(比较运算符)。Compares two expressions (a comparison operator) in SQL Server 2019 (15.x)SQL Server 2019 (15.x). 当比较非空表达式时,如果左操作数的值大于右操作数,则结果为 TRUE;否则结果为 FALSE。When you compare nonnull expressions, the result is TRUE if the left operand has a value higher than the right operand; otherwise, the result is FALSE. 如果任何一个操作数为 NULL 或两个都为 NULL,则请参阅主题 SET ANSI_NULLS (Transact-SQL)If either or both operands are NULL, see the topic SET ANSI_NULLS (Transact-SQL).

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

expression > expression  

参数Arguments

expressionexpression
为任意有效的表达式Is any valid expression. 两个表达式都必须包含可隐式转换的数据类型。Both expressions must have implicitly convertible data types. 转换方式取决于数据类型优先级的相关规则。The conversion depends on the rules of data type precedence.

结果类型Result Types

布尔值Boolean

示例Examples

A.A. 在简单查询中使用 >Using > in a simple query

下面的示例返回 HumanResources.Department 表中其 DepartmentID 的值大于 13 的所有行。The following example returns all rows in the HumanResources.Department table that have a value in DepartmentID that is greater than the value 13.

--Uses AdventureWorks  
  
SELECT DepartmentID, Name  
FROM HumanResources.Department  
WHERE DepartmentID > 13  
ORDER BY DepartmentID;  
  

下面是结果集:Here is the result set.

DepartmentID Name  
------------ --------------------------------------------------  
14           Facilities and Maintenance  
15           Shipping and Receiving  
16           Executive  
  
(3 row(s) affected)  
  

B.B. 使用 > 比较两个变量Using > to compare two variables

DECLARE @a int = 45, @b int = 40;  
SELECT IIF ( @a > @b, 'TRUE', 'FALSE' ) AS Result;  
  

下面是结果集:Here is the result set.

Result  
------  
TRUE  
  
(1 row(s) affected)  
  

另请参阅See Also

IIF (Transact-SQL) IIF (Transact-SQL)
数据类型 (Transact-SQL) Data Types (Transact-SQL)
运算符 (Transact-SQL)Operators (Transact-SQL)