Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用mysql从表中提取最近的最小或最大行?_Mysql - Fatal编程技术网

如何使用mysql从表中提取最近的最小或最大行?

如何使用mysql从表中提取最近的最小或最大行?,mysql,Mysql,我的Mysql数据库: | time | Name | TYU | 1483347398 | vprasad | PDSP_DES

我的Mysql数据库:

| time       | Name     | TYU
| 1483347398 | vprasad  | PDSP_DES                                                                                                                                                                                                                       
| 1483348583 | akawle   | LPT                                                                                                                                                                                                                                                                                                                              
**我的问题是:

我已经使用select*from users查询来检索上面的表。现在我需要根据表名的最短或最长时间从数据库中输出整行

到目前为止,我试过:

我尝试了下面的查询select mintime from users。我不知道如何使用mintime或使用mysql检索整行

我的输出:

我的预期产出:

你应该试试这个:

从用户中选择mintime作为min_time、name、TYU

结果是: 1483347398 | vprasad | PDSP | DES

因为在1483348583和1483347398中,1483347398是最小值

如果您希望得到如下结果: 1483348583 akawle LPT

你应该试试这个: 从用户中选择maxtime作为min_time、name、TYU

如果需要所有行,则可以这样尝试:


从用户订单中按时间asc选择时间、名称、TYU

您可以使用排序方法

SELECT * FROM users ORDER BY time ASC LIMIT 1
按ASC排序以获得最小值作为第一个结果 限制1,这样你只得到一个最小的结果 给你

SELECT time, name, TYU FROM users WHERE time = (select min(time) from users)

在输出时,请尝试以下操作:-

最长时间

最短时间


检查小提琴:-

从用户处选择时间、名称、TYU,其中time=MINTIME显示错误为组的有效使用funciton@manny
SELECT * FROM users ORDER BY time ASC LIMIT 1
SELECT time, name, TYU FROM users WHERE time = (select min(time) from users)
select time,Name,TYU from tt where time = (select max(time) from tt);
select time,Name,TYU from tt where time = (select min(time) from tt);