Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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_Sql - Fatal编程技术网

Mysql 选择子查询

Mysql 选择子查询,mysql,sql,Mysql,Sql,在过去的一个小时里我一直在窃听这个 我想从表clickednumbers的最新数据中获得前5名 clickednumbers只能将数字列作为INT和numberTime列作为时间戳 我的问题 SELECT AVG( SELECT * FROM clickednumbers ORDER BY numberTime DESC LIMIT 5) FROM clickednumbers 我总是犯错误 1064-您的SQL语法有错误

在过去的一个小时里我一直在窃听这个

我想从表clickednumbers的最新数据中获得前5名

clickednumbers只能将数字列作为INT和numberTime列作为时间戳

我的问题

SELECT AVG( SELECT *
            FROM clickednumbers
            ORDER BY numberTime DESC
            LIMIT 5)
FROM clickednumbers
我总是犯错误

1064-您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以获取要使用的正确syntanx '选择* 从点击的数字 按编号订购时间描述' 在1号线

MariaDB版本:服务器类型:MariaDB 服务器版本:10.1.9-MariaDB-MariaDB.org二进制发行版 协议版本:10

很抱歉打扰您:


目标:要根据NumberTime从最新数字中获得前5名的平均值,请在from子句中使用子查询:

查看更多关于发生了什么的想法。我认为您的查询需要看起来更像这样:

SELECT AVG(x.numbers) 
  FROM (SELECT numbers FROM clickednumbers ORDER BY numberTime DESC
  LIMIT 5) as x
SELECT AVG(x.numbers) 
  FROM (SELECT numbers FROM clickednumbers ORDER BY numberTime DESC
  LIMIT 5) as x