找到关于 MySQL 的4379 篇文章
211 次浏览
要在 MySQL 中减去一天,可以使用 DATE_SUB() 方法。让我们先创建一个表:mysql> create table DemoTable -> ( -> AdmissionDate timestamp -> ); Query OK, 0 rows affected (1.05 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('2019-01-01'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2017-03-13'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-01-02'); Query OK, 1 row affected (0.08 sec) 使用 select ... 阅读更多
263 次浏览
不可以。要解决这个问题,请在字段名周围使用反引号。让我们先创建一个包含星号作为列名的表,`Name*`:mysql> create table DemoTable -> ( -> `Name*` varchar(20) -> ); Query OK, 0 rows affected (2.03 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable(`Name*`) values('Chris Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(`Name*`) values('David Miller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(`Name*`) values('John Doe'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(`Name*`) values('John Smith'); ... 阅读更多
94 次浏览
为此,您可以使用 SOUND 以及 LIKE 运算符。让我们先创建一个表:mysql> create table DemoTable -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.95 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values('Johm'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('SAMSUNG'); Query ... 阅读更多
603 次浏览
要替换不存在的记录,请在 MySQL 中使用 COALESCE。COALESCE 将有助于替换 NULL 值。让我们先创建一个表:mysql> create table DemoTable -> ( -> Code varchar(20) -> ); Query OK, 0 rows affected (1.64 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('45'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('78'); Query OK, 1 row affected (0.21 sec) 使用 select 语句显示表中的所有记录 ... 阅读更多
124 次浏览
让我们先创建一个表:mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.82 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(201, 'Chris Brown'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(110, 'John Doe'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values(101, 'Adam Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(345, 'Carol Taylor'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(135, ... 阅读更多
93 次浏览
让我们先创建一个表:mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.77 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(78, 89); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(19, null); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(null, 0); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(null, 95); Query OK, 1 row affected (0.15 sec) 使用 select 语句显示表中的所有记录:mysql> ... 阅读更多
387 次浏览
为此,您可以使用 CASE WHEN 语句。让我们先创建一个表:mysql> create table DemoTable -> ( -> FirstName varchar(20), -> Score int -> ); Query OK, 0 rows affected (0.63 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('John', 46); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('John', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('John', 69); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 78); Query OK, 1 row affected (0.12 ... 阅读更多
115 次浏览
让我们先创建一个表:mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstName varchar(20) -> ); Query OK, 0 rows affected (0.65 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName) values('Adam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(FirstName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 ... 阅读更多
342 次浏览
要查找两个 datetime 值之间的差异,可以使用 TIMESTAMPDIFF()。让我们先创建一个表:mysql> create table DemoTable -> ( -> DueDatetime1 datetime, -> DueDatetime2 datetime -> ); Query OK, 0 rows affected (0.86 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('2019-10-26 19:49:00', '2019-10-26 17:49:00'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-10-26 08:00:00', '2019-10-26 13:00:00'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-10-26 06:50:00', '2019-10-26 12:50:00'); Query OK, 1 row affected (0.68 sec) 显示表中的所有记录 ... 阅读更多
121 次浏览
让我们先创建一个表:mysql> create table DemoTable -> ( -> DueDate date ->); Query OK, 0 rows affected (2.11 sec) 使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('2019-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('2018-12-30'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('2017-02-26'); Query OK, 1 row affected (0.47 sec) 使用 select 语句显示表中的所有记录:mysql> select *from DemoTable; 这将产生以下输出:+------------+ ... 阅读更多