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

数値をvarcharフィールドとして設定し、MySQLで比較します


まずテーブルを作成しましょう-

mysql> create table DemoTable
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentScore varchar(100)
   -> );
Query OK, 0 rows affected (0.66 sec)

挿入コマンド-

を使用して、テーブルにいくつかのレコードを挿入します
mysql> insert into DemoTable(StudentScore) values('90');
Query OK, 1 row affected (0.21 sec)

mysql> insert into DemoTable(StudentScore) values('100');
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable(StudentScore) values('56');
Query OK, 1 row affected (0.10 sec)

mysql> insert into DemoTable(StudentScore) values('98');
Query OK, 1 row affected (0.13 sec)

selectステートメントを使用してテーブルのすべてのレコードを表示します-;

mysql> select *from DemoTable;

出力

+-----------+--------------+
| StudentId | StudentScore |
+-----------+--------------+
|         1 | 90           |
|         2 | 100          |
|         3 | 56           |
|         4 | 98           |
+-----------+--------------+
4 rows in set (0.00 sec)

これがvarcharフィールドで比較するクエリです-

mysql> select *from DemoTable where  CAST(StudentScore AS SIGNED) > 91;

出力

+-----------+--------------+
| StudentId | StudentScore |
+-----------+--------------+
|         2 | 100          |
|         4 | 98           |
+-----------+--------------+
2 rows in set (0.00 sec)

  1. MySQLで文字列と数値を含むVARCHARレコードを注文する

    これには、ORDERBY句を使用します。まずテーブルを作成しましょう- mysql> create table DemoTable    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable values('101J'); Query OK, 1 row a

  2. MySQLでDOUBLEの長さを実装および設定する

    MySQLでDOUBLEを実装するための構文は、次のとおりです- create table yourTableName      (      yourColumnName double(5,2) unsigned );を作成します まずテーブルを作成しましょう- mysql> create table DemoTable1814      (      Amount double(5,2) unsigned      ); Query