Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

MySQL에서 HAVING LENGTH(필드)를 구현하는 방법은 무엇입니까?

<시간/>

먼저 테이블을 생성하겠습니다 -

mysql> create table DemoTable
(
   Title text
);
Query OK, 0 rows affected (0.39 sec)

삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -

mysql> insert into DemoTable values('Introduction to MySQL');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('Introduction to Java');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('Introduction to SQL');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Introduction to Python');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Introduction to SQL');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('Introduction to Java');
Query OK, 1 row affected (0.13 sec)

select 문을 사용하여 테이블의 모든 레코드 표시 -

mysql> select *from DemoTable;

이것은 다음과 같은 출력을 생성합니다 -

+------------------------+
| Title                  |
+------------------------+
| Introduction to MySQL  |
| Introduction to Java   |
| Introduction to SQL    |
| Introduction to Python |
| Introduction to SQL    |
| Introduction to Java   |
+------------------------+
6 rows in set (0.00 sec)

다음은 MySQL에서 HAVING LENGTH(field)를 구현하는 쿼리입니다 -

mysql> select *from DemoTable group by length(Title)
   having length(Title) < 21;

이것은 다음과 같은 출력을 생성합니다 -

+----------------------+
| Title                |
+----------------------+
| Introduction to SQL  |
| Introduction to Java |
+----------------------+
2 rows in set (0.00 sec)