MySQL
 Computer >> コンピューター >  >> プログラミング >> MySQL

開始点と終了点のないMySQL?


開始値と終了値を間に含めたくない場合は、次の構文を使用します-

SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and
   yourColumnName not in (yourStartingValue , yourEndingValue );

上記の構文を理解するために、テーブルを作成しましょう。テーブルを作成するためのクエリは次のとおりです-

mysql> create table BetweenWithoutEndPoints
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> Age int,
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.54 sec)

これで、insertコマンドを使用してテーブルにいくつかのレコードを挿入できます。クエリは次のとおりです-

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Mike',23);
Query OK, 1 row affected (0.21 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Larry',25);
Query OK, 1 row affected (0.21 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('David',28);
Query OK, 1 row affected (0.16 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Sam',26);
Query OK, 1 row affected (0.15 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Carol',21);
Query OK, 1 row affected (0.14 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('John',29);
Query OK, 1 row affected (0.18 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('James',20);
Query OK, 1 row affected (0.41 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Robert',26);
Query OK, 1 row affected (0.17 sec)

mysql> insert into BetweenWithoutEndPoints(Name,Age) values('Michael',30);
Query OK, 1 row affected (0.16 sec)

selectステートメントを使用して、テーブルのすべてのレコードを表示します。クエリは次のとおりです-

mysql> select *from BetweenWithoutEndPoints;

以下は出力です。

+----+---------+------+
| Id | Name    | Age  |
+----+---------+------+
| 1  | Mike    | 23   |
| 2  | Larry   | 25   |
| 3  | David   | 28   |
| 4  | Sam     | 26   |
| 5  | Carol   | 21   |
| 6  | John    | 29   |
| 7  | James   | 20   |
| 8  | Robert  | 26   |
| 9  | Michael | 30   |
+----+---------+------+
9 rows in set (0.00 sec)

これは、開始点と終了点を取得せずに実行するMySQLのクエリです。以下のクエリには、3と8は含まれていません:

mysql> select *from BetweenWithoutEndPoints
-> where Id between 3 and 8 and Id not in (3, 8);

出力は次のとおりです。

+----+-------+------+
| Id | Name  | Age  |
+----+-------+------+
| 4  | Sam   | 26   |
| 5  | Carol | 21   |
| 6  | John  | 29   |
| 7  | James | 20   |
+----+-------+------+
4 rows in set (0.04 sec)

  1. MySQLのTINYINT(1)とブール値の違いは何ですか?

    TINYINT(1)とブール値の間に違いはありません。キーワードBoolまたはBooleanは内部でTINYINT(1)に変換されます。または、BoolまたはBooleanはTINYINT(1)と同義であると言えます。 まずテーブルを作成しましょう- mysql> create table DemoTable (    isMarried Boolean ); Query OK, 0 rows affected (1.77 sec) 表の説明を確認しましょう- mysql> desc DemoTable; これにより、次の出力が生成されます- +-----

  2. MySQLでは、!=NULLとISNOT NULLの違いは何ですか?

    値を!=NULLと比較すると、NULLが返されます。したがって、!=NULLは無意味です。 !=NULLとISNOT NULLの違いを確認するために、最初にテーブルを作成しましょう。 まずテーブルを作成しましょう- mysql> create table DemoTable1970    (    Value int    ); Query OK, 0 rows affected (0.00 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTa