找到 4379 篇文章 关于 MySQL
103 次浏览
要在 MySQL 中按日期分组,请使用 GROUP BY 子句 −mysql> create table DemoTable2002 ( CustomerName varchar(20), CustomerShippingDate datetime ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable2002 values('Chris', '2019-01-10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2002 values('David', '2018-12-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('David', '2019-12-16'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('Chris', '2018-12-01'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录 −mysql> select * ... 阅读更多
78 次浏览
要使用用户定义变量获取最大考试日期,代码如下:select date(max(yourColumnName )) into @yourVariableName from yourTableName;为了理解上述语法,让我们首先创建一个表 −mysql> create table DemoTable2001 ( ExamDate date ); Query OK, 0 rows affected (0.60 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable2001 values('2019-01-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2001 values('2018-12-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2001 values('2018-11-18'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable2001 values('2019-07-25'); Query OK, 1 ... 阅读更多
316 次浏览
要显示正确的单引号,需要使用 COLLATE='utf8_unicode_ci' 修改表。让我们首先创建一个表 −mysql> create table DemoTable2000 ( Name varchar(20) ); Query OK, 0 rows affected (0.81 sec)以下是使用 collate 的查询 −mysql> ALTER TABLE DemoTable2000 COLLATE='utf8_unicode_ci'; Query OK, 0 rows affected (0.90 sec) Records: 0 Duplicates: 0 Warnings: 0使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable2000 values('Chris’s Brown'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable2000 values('David’s Miller'); Query OK, 1 row affected (0.67 sec) mysql> insert into DemoTable2000 values('Robert’s Downey'); Query ... 阅读更多
173 次浏览
要仅返回月份名称,可以使用 DATE_FORMAT() −mysql> create table DemoTable1999 ( ArrivalDate timestamp ); Query OK, 0 rows affected (0.66 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1999 values('2019-01-01 12:34:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1999 values('2019-12-31 10:04:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1999 values('2018-10-11 04:04:30'); Query OK, 1 row affected (0.14 sec)使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1999;这将产生以下输出:+---------------------+ | ArrivalDate | +---------------------+ ... 阅读更多
884 次浏览
要从重复的行中只返回一行,请使用 DISTINCT 关键字 −mysql> create table DemoTable1998 ( Name varchar(20) ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1998 values('David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1998 ... 阅读更多
720 次浏览
要将日期转换为 UNIX 时间戳,请在 MySQL 中使用 UNIX_TIMESTAMP() −mysql> create table DemoTable1997 ( DueDate date ); Query OK, 0 rows affected (0.58 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1997 values('2018-10-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2019-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2017-01-31'); Query OK, 1 row affected (0.11 sec)使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1997;这将产生以下输出:+------------+ | DueDate | +------------+ | 2018-10-11 | | 2019-12-21 | ... 阅读更多
167 次浏览
让我们创建一个表 −mysql> create table DemoTable1996 ( ShippingDate datetime, CustomerName varchar(20) ); Query OK, 0 rows affected (0.84 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1996 values('2019-12-21 10:45:00', 'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1996 values('2019-12-21 12:10:00', 'David'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1996 values('2019-12-20 12:10:00', 'Bob'); Query OK, 1 row affected (0.14 sec)使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1996;这将产生以下输出:+---------------------+--------------+ | ShippingDate | CustomerName ... 阅读更多
364 次浏览
让我们首先创建一个表 −mysql> create table DemoTable1994 ( ArrivalDate date ); Query OK, 0 rows affected (5.33 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1994 values('2019-12-18'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1994 values('2019-12-19'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable1994 values('2019-12-20'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable1994 values('2019-12-25'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1994 values('2018-12-20'); Query OK, 1 row affected (1.42 sec)使用 select 语句显示表中的所有记录 −mysql> select ... 阅读更多
134 次浏览
使用 if else 为枚举设置自定义消息。让我们首先创建一个表 −mysql> create table DemoTable1992 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), isActive ENUM('Y', 'N') ); Query OK, 0 rows affected (0.89 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1992(ClientName, isActive) values('Chris', 'N'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('Bob', 'N'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('David', 'Y'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('Carol', ... 阅读更多
714 次浏览
为此,您可以使用 NOT IN() −mysql> create table DemoTable1991 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable1991(StudentName) values('Chris'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1991(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1991(StudentName) values('David'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1991(StudentName) values('Sam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1991(StudentName) values('Mike'); Query OK, 1 row affected (0.11 sec)显示所有 ... 阅读更多