Sql-operators
SQL-演算子
SQLの演算子とは何ですか?
演算子は、比較や算術演算などの操作を実行するためにSQLステートメントのWHERE句で主に使用される予約語または文字です。 これらの演算子は、SQLステートメント内の条件を指定し、ステートメント内の複数の条件の組み合わせとして機能するために使用されます。
- 算術演算子
- 比較演算子
- 論理演算子
- 条件を否定するために使用される演算子
SQL算術演算子
*'変数a'* が10を保持し、 *'変数b'* が20を保持すると仮定します-
link:/sql/sql-arithmetic-operators [例を表示]
Operator | Description | Example |
---|---|---|
+ (Addition) | Adds values on either side of the operator. | a + b will give 30 |
- (Subtraction) | Subtracts right hand operand from left hand operand. | a - b will give -10 |
*(Multiplication) | Multiplies values on either side of the operator. | a* b will give 200 |
/(Division) | Divides left hand operand by right hand operand. | b/a will give 2 |
% (Modulus) | Divides left hand operand by right hand operand and returns remainder. | b % a will give 0 |
SQL比較演算子
*'変数a'* が10を保持し、 *'変数b'* が20を保持すると仮定します-
link:/sql/sql-comparison-operators [例を表示]
Operator | Description | Example |
---|---|---|
= | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (a = b) is not true. |
!= | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a != b) is true. |
<> | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a <> b) is true. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (a > b) is not true. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (a < b) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (a >= b) is not true. |
⇐ | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (a ⇐ b) is true. |
!< | Checks if the value of left operand is not less than the value of right operand, if yes then condition becomes true. | (a !< b) is false. |
!> | Checks if the value of left operand is not greater than the value of right operand, if yes then condition becomes true. | (a !> b) is true. |
SQL論理演算子
以下は、SQLで使用可能なすべての論理演算子のリストです。
link:/sql/sql-logical-operators [例を表示]
Sr.No. | Operator & Description |
---|---|
1 |
ALL ALL演算子は、値を別の値セットのすべての値と比較するために使用されます。 |
2 |
AND AND演算子を使用すると、SQLステートメントのWHERE句に複数の条件を含めることができます。 |
3 |
ANY ANY演算子は、条件に従って値をリスト内の適用可能な値と比較するために使用されます。 |
4 |
BETWEEN BETWEEN演算子は、最小値と最大値を指定して、値のセット内にある値を検索するために使用されます。 |
5 |
EXISTS EXISTS演算子は、特定の条件を満たす特定のテーブル内の行の存在を検索するために使用されます。 |
6 |
IN IN演算子は、値を指定されたリテラル値のリストと比較するために使用されます。 |
7 |
LIKE LIKE演算子は、ワイルドカード演算子を使用して値を同様の値と比較するために使用されます。 |
8 |
NOT NOT演算子は、使用される論理演算子の意味を逆にします。 例:存在しない、間にない、中にないなど *これは否定演算子です。 * |
9 |
OR演算子は、SQLステートメントのWHERE句で複数の条件を結合するために使用されます。 |
10 |
IS NULL NULL演算子は、値をNULL値と比較するために使用されます。 |
11 |
UNIQUE UNIQUE演算子は、指定されたテーブルのすべての行の一意性(重複なし)を検索します。 |