找到 4379 篇文章 关于 MySQL

删除时间戳早于 5 分钟的记录?

AmitDiwan
更新于 2019-12-26 06:28:28

2K+ 次浏览

为此,使用 DELETE 命令。让我们首先创建一个表 −mysql> create table DemoTable1851      (      DueDate datetime      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1851 values('2019-12-03 21:30:35'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1851 values('2019-12-03 21:45:00'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1851 values('2019-12-03 21:34:00'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1851; 这将产生以下输出 −+---------------------+ | ... 阅读更多

MySQL IF() 函数显示自定义的“是”或“否”消息

AmitDiwan
更新于 2019-12-26 06:27:07

582 次浏览

让我们首先创建一个表 −mysql> create table DemoTable1850      (      OrderStatus varchar(20)      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1850 values('Yes'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1850 values('No'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1850 values('Yes'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1850 values('Yes'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1850; 这将产生... 阅读更多

MySQL 查询:在获取数据时,用空字符串替换多个列中的 NULL 值

AmitDiwan
更新于 2019-12-26 06:26:03

1K+ 次浏览

为此,可以使用 IFNULL() 或 COALESCE()。让我们首先创建一个表 −mysql> create table DemoTable1849      (      ClientFirstName varchar(20),      ClientLastName varchar(20)      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1849 values('John', NULL); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1849 values(NULL, 'Miller'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1849 values(NULL, NULL); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1849 values('Chris', 'Brown'); 查询成功,1 行受影响 (0.00 秒) 显示... 阅读更多

如何在 MySQL 中向设置为 DATETIME 类型的列添加时间?

AmitDiwan
更新于 2019-12-26 06:23:48

771 次浏览

要向 datetime 添加时间,请在 MySQL 中使用 ADDTIME() 函数。让我们首先创建一个表 −mysql> create table DemoTable1848      (      ShippingDate datetime      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1848 values('2019-10-11 12:30:45'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1848 values('2019-01-12 10:00:00'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1848 values('2019-12-03 17:30:00'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1848; 这将产生... 阅读更多

在 MySQL 查询中向列添加用户定义的值?

AmitDiwan
更新于 2019-12-26 06:22:14

401 次浏览

让我们首先创建一个表 −mysql> create table DemoTable1847      (      GameStatus ENUM('PENDING', 'COMPLETED', 'CANCELLED')      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1847 values('PENDING'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1847 values('COMPLETED'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1847 values('CANCELLED'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1847; 这将产生以下输出 −+------------+ | GameStatus | +------------+ | PENDING   ... 阅读更多

MySQL 获取基于特定月份和年份的记录?

AmitDiwan
更新于 2019-12-26 06:20:06

713 次浏览

为此,使用 MONTH() 和 YEAR()。让我们首先创建一个表 −mysql> create table DemoTable1846      (      PurchaseDate date      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1846 values('2019-01-10'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1846 values('2019-12-24'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1846 values('2018-09-21'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1846 values('2017-10-26'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * ... 阅读更多

在 MySQL 中选择今天之前 15 天的记录?

AmitDiwan
更新于 2019-12-26 06:18:48

840 次浏览

为此,可以使用 INTERVAL 和 DATE_SUB() 的概念。让我们首先创建一个表 −mysql> create table DemoTable1845      (      ArrivalDate date      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1845 values('2019-12-02'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1845 values('2019-11-18'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1845 values('2019-12-18'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1845 values('2019-12-25'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1845 values('2019-11-15'); Query ... 阅读更多

在 MySQL 查询中计算百分比并四舍五入结果

AmitDiwan
更新于 2019-12-26 06:15:48

3K+ 次浏览

为此,可以使用 CONCAT() 和 round()。让我们首先创建一个表 −mysql> create table DemoTable1844      (      Number int,      TotalNumber int      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1844 values(50, 500); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1844 values(80, 500); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1844 values(98, 500); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1844 values(45, 500); 查询成功,1 行受影响 (0.00 秒) 显示... 阅读更多

在 MySQL 中获取特定年份的开始日期和结束日期

AmitDiwan
更新于 2019-12-26 06:11:02

435 次浏览

为此,使用 MySQL YEAR() 函数。让我们首先创建一个表 −mysql> create table DemoTable1843      (      StartDate date,      EndDate date      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1843 values('2019-01-21', '2019-10-12'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1843 values('2018-10-12', '2018-12-31'); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1843 values('2016-04-01', '2017-05-02'); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1843;这将产生... 阅读更多

在 MySQL 中将列与 NULL 行相乘?

AmitDiwan
更新于 2019-12-26 06:04:14

408 次浏览

要与 NULL 行相乘,可以使用 COALESCE()。让我们首先创建一个表 −mysql> create table DemoTable1842      (      NumberOfItems int,      Amount int      ); 查询成功,0 行受影响 (0.00 秒) 使用 insert 命令插入一些记录 −mysql> insert into DemoTable1842 values(10, 40); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1842 values(20, 5); 查询成功,1 行受影响 (0.00 秒) mysql> insert into DemoTable1842 values(NULL, 10); 查询成功,1 行受影响 (0.00 秒) 使用 select 语句显示表中的所有记录 −mysql> select * from DemoTable1842;这... 阅读更多

广告
© . All rights reserved.