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

MySQLで合計値から200文字だけを表示するにはどうすればよいですか?


MySQLのLEFT()を使用して、MySQLの値全体の一部の文字を表示できます。構文は次のとおりです。

select left(yourColumnName ,200 ) AS anyAliasName from yourTableName;

最初にテーブルを作成しましょう:

mysql> create table DemoTable (Paragraph longtext);
Query OK, 0 rows affected (0.71 sec)

以下は、挿入コマンドを使用してテーブルにレコードを挿入するためのクエリです。

mysql> insert into DemoTable values('Introduction to Java,Introduction to C,Introduction to
C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to
MySQL,Introduction to MongoDB,Introduction to SQL Server,Introduction to
ASP.net,Introduction to JSF');
Query OK, 1 row affected (0.13 sec)

以下は、selectコマンドを使用してテーブルのレコードを表示するためのクエリです。

mysql> select *from DemoTable;

これにより、次の出力が生成されます。

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Paragraph                                                                                                                                                                                                                                                               |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Server,Introduction to ASP.net,Introduction to JSF                |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

以下は、合計値から200文字のみを表示するためのクエリです。

mysql> select left(Paragraph ,200) AS `200Characters` from DemoTable;

これにより、最初の200文字のみを表示する次の出力が生成されます。

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 200Characters                                                                                                                                                                                                                         |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Ser                                                                                                                                                                                                        |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

  1. MySQLのタイムスタンプ値からの日付のみを表示する

    タイムスタンプ値からの唯一の日付を表示するには、MySQLのFROM_UNIXTIME()メソッドを使用します。まずテーブルを作成しましょう- mysql> create table DemoTable    -> (    -> timestampValue bigint    -> ); Query OK, 0 rows affected (0.70 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable values(

  2. MySQLの別のフィールドからフィールドの値を導出する方法は?

    このために、ユーザー定義変数の概念を使用できます。まずテーブルを作成しましょう- mysql> create table DemoTable1868      (      Value int      ); Query OK, 0 rows affected (0.00 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable1868 values(10); Query OK, 1 row affected (0