找到 4379 篇文章 关于 MySQL
115 次浏览
要在 MySQL 中只返回一次列值,让我们首先看一个例子并创建一个表:mysql> create table DemoTable680(Status varchar(100)); Query OK, 0 rows affected (0.75 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable680 values('Busy'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable680 values('At Work'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable680 values('Busy'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable680 values('Blocked'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable680 values('Offline'); Query OK, 1 row affected (0.67 sec) ... 阅读更多
86 次浏览
让我们首先创建一个表:mysql> create table DemoTable679(FirstName varchar(100)); Query OK, 0 rows affected (0.44 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable679 values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable679 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable679 values('David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable679 values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable679 values('Mike'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable679 values('Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert ... 阅读更多
493 次浏览
为此,请在 MySQL 中使用 ORDER BY STR_TO_DATE,如下面的语法所示:select *from yourTableName ORDER BY STR_TO_DATE(yourColumnName, '%M %Y') DESC; 让我们首先创建一个表:mysql> create table DemoTable678(DueDate varchar(200)); Query OK, 0 rows affected (0.62 sec) 使用 insert 命令在表中插入一些记录。我们在这里插入了日期:mysql> insert into DemoTable678 values('March 2019'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable678 values('November 2018'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable678 values('January 2019'); Query OK, 1 row affected (0.18 sec) 使用 select 语句显示表中的所有记录:mysql> ... 阅读更多
365 次浏览
要设置自定义字段值,请使用 FIND_IN_SET()。让我们首先创建一个表:mysql> create table DemoTable677( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserStatus text ); Query OK, 0 rows affected (1.07 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable677(UserStatus) values('BUSY'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable677(UserStatus) values('AT WORK'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable677(UserStatus) values('OFFLINE'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable677(UserStatus) values('BLOCKED'); Query OK, 1 row affected (0.17 sec) 使用 select ... 阅读更多
467 次浏览
CONCAT() 方法用于将“MR”连接到每个字符串,而 GROUP_CONCAT() 用于将某些列值连接到一行。让我们首先看一个例子并创建一个表:mysql> create table DemoTable799( UserId int, UserName varchar(100), UserAge int ); Query OK, 0 rows affected (0.56 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable799 values(101, 'John', 21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable799 values(102, 'Chris', 26); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable799 values(101, 'Robert', 23); Query OK, ... 阅读更多
181 次浏览
让我们首先创建一个表:mysql> create table DemoTable676( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Number int ); Query OK, 0 rows affected (0.50 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable676(Number) values(1000); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable676(Number) values(1839); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable676(Number) values(29894); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable676(Number) values(1264); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable676(Number) values(190); Query OK, 1 row affected (0.17 sec) mysql> insert into ... 阅读更多
410 次浏览
要搜索逗号分隔值的表,请使用 LIKE 运算符。让我们首先创建一个表:mysql> create table DemoTable675(Value text); Query OK, 0 rows affected (0.55 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable675 values('10, 56, 49484, 93993, 211, 4594'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable675 values('4, 7, 1, 10, 90, 23'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable675 values('90, 854, 56, 89, 10'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable675 values('11, 22, 344, 67, 89'); Query OK, 1 row ... 阅读更多
68 次浏览
是的,我们可以在 insert 语句中命名列。让我们首先创建一个表:mysql> create table DemoTable674( StudentId int, StudentFirstName varchar(100), StudentLastName varchar(100) ); Query OK, 0 rows affected (0.82 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable674 set StudentId=10, StudentFirstName='John', StudentLastName='Smith'; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable674 set StudentId=11, StudentFirstName='Carol', StudentLastName='Taylor'; Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable674 set StudentId=12, StudentFirstName='David', StudentLastName='Miller'; Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable674 set StudentId=13, StudentFirstName='Chris', StudentLastName='Brown'; Query OK, 1 ... 阅读更多
1K+ 次浏览
为此,请使用 GROUP BY HAVING 子句。让我们首先创建一个表:mysql> create table DemoTable673( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (0.59 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable673(Value) values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable673(Value) values(20); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable673(Value) values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable673(Value) values(30); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable673(Value) values(20); Query OK, 1 ... 阅读更多
254 次浏览
为此,使用 order by nullif()。让我们先创建一个表:
mysql> create table DemoTable672(
CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
CustomerName varchar(100),
CustomerAmount int );
Query OK, 0 rows affected (0.81 sec)
使用 insert 命令在表中插入一些记录:
mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('Chris', 560);
Query OK, 1 row affected (0.51 sec)
mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('Robert', null);
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('', 450);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable672(CustomerName, CustomerAmount) values('David', 456);
Query OK, 1 row affected ... 阅读更多