找到 4379 篇文章 关于 MySQL

在 MySQL 中根据另一个包含重复值的列进行分组,获取时间戳中的第一个日期

AmitDiwan
更新于 2019-12-27 06:04:31

248 次浏览

为此,您可以使用聚合函数 MIN() 和 GROUP BY。让我们先创建一个表 -mysql> create table DemoTable1870      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Value int,      ShippingTimestamp varchar(100)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1570645800'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1546194600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(11, '1573324200'); Query OK, 1 row affected (0.00 ... 阅读更多

在 MySQL 中连接同一列中具有不同条件的两个值

AmitDiwan
更新于 2019-12-26 07:35:39

983 次浏览

为此,您可以使用带聚合函数的 group_concat()。让我们先创建一个表 -mysql> create table DemoTable1869      (      Id int,      Subject varchar(20 ),      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1869 values(100, 'MySQL', 'John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(100, 'MongoDB', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(101, 'MySQL', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(101, ... 阅读更多

如何在 MySQL 中从另一个字段派生字段的值?

AmitDiwan
更新于 2019-12-26 07:31:05

339 次浏览

为此,您可以使用用户定义变量的概念。让我们先创建一个表 -mysql> create table DemoTable1868      (      Value int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1868 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(20); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(40); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 ... 阅读更多

如何在 MySQL 中列出所有由 SET 运算符初始化的变量?

AmitDiwan
更新于 2019-12-26 07:22:55

263 次浏览

要列出所有由 SET 运算符初始化的变量,语法如下 -select * from performance_schema.user_variables_by_thread;以下是设置变量的查询 -mysql> set @FirstName='John'; Query OK, 0 rows affected (0.00 sec) mysql> set @LastName='Doe'; Query OK, 0 rows affected (0.00 sec)以下是显示由 SET 运算符初始化的所有变量列表的查询。此列表包含上面设置的变量 -mysql> select * from performance_schema.user_variables_by_thread;这将产生以下输出 -+-----------+---------------+----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+----------------+ |       120 | TotalAmount   |           5000 | ... 阅读更多

使用 MySQL 查询将日期/时间值按秒递增?

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

480 次浏览

为此,请使用带 interval 命令的 date_add()。让我们先创建一个表 -mysql> create table DemoTable1867      (      ArrivalTime datetime      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 10:04:15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 11:00:23'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1867; 这将产生以下输出 ... 阅读更多

MySQL 查询,从一个列获取字符串,并在另一个列中查找其在逗号分隔值中的位置?

AmitDiwan
更新于 2019-12-26 07:19:48

265 次浏览

为此,请使用 FIND_IN_SET()。让我们先创建一个表 -mysql> create table DemoTable1866      (      Value1 int,      ListOfValues varchar(100)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1866 values(56, '78, 56, 98, 95'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(103, '103, 90, 102, 104'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(77, '34, 45, 77, 78'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> ... 阅读更多

尝试在 MySQL 的新列中将计算结果四舍五入到小数点后两位?

AmitDiwan
更新于 2019-12-26 07:18:00

458 次浏览

要进行四舍五入,请使用 MySQL ROUND() 函数。让我们先创建一个表 -mysql> create table DemoTable1865      (      Value1 int,      Value2 int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1865 values(40, 60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(100, 400); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(545, 896); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1865;这将产生 ... 阅读更多

如何将 MySQL 查询的结果分配给变量?

AmitDiwan
更新于 2019-12-26 07:16:28

890 次浏览

使用 @anyVariableName 将查询的结果分配给变量。让我们先创建一个表 -mysql> create table DemoTable1864      (      Id int,      FirstName varchar(20),      LastName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1864 values(101, 'Chris', 'Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1864 values(102, 'David', 'Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1864 values(103, 'Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多

如何在 MySQL 中为空行设置默认值?

AmitDiwan
更新于 2019-12-26 06:54:31

595 次浏览

要为空行设置默认值,请使用 COALESCE() 的概念。让我们先创建一个表 -mysql> create table DemoTable1863      (      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1863 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values(NULL); Query OK, 1 row affected (0.00 sec)显示表中的所有记录 ... 阅读更多

如何使用 MySQL 查找一组列中具有空值的行

AmitDiwan
更新于 2019-12-26 06:51:44

167 次浏览

为此,使用 GREATEST() 的概念。让我们首先创建一个表 -mysql> create table DemoTable1862      (      Value1 int,      Value2 int,      Value3 int,      Value4 int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1862 values(43, 34, 56, 42); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1862 values(NULL, 78, 65, NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1862 values(110, NULL, 78, NULL); Query OK, 1 row affected (0.00 sec)显示所有 ... 阅读更多

广告