每当在MySQL Benchmark中返回多行时解决错误?
每当您在基准测试中返回多行时,都会出现错误。返回标量值或单行而不是多行。语法如下-
SELECT yourColumnName FROM yourTableName WHERE yourCondition.
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table UserDemo -> ( -> UserId int, -> UserName varchar(20), -> RegisteredCourse varchar(10) -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into UserDemo values(1,'John','Java'); mysql> insert into UserDemo values(2,'Larry','C'); mysql> insert into UserDemo values(3,'Carol','C++'); mysql> insert into UserDemo values(4,'Mike','C#');
使用select语句显示表中的所有记录。查询如下-
mysql> select *from UserDemo;
以下是输出-
+--------+----------+------------------+ | UserId | UserName | RegisteredCourse | +--------+----------+------------------+ | 1 | John | Java | | 2 | Larry | C | | 3 | Carol | C++ | | 4 | Mike | C# | +--------+----------+------------------+ 4 rows in set (0.00 sec)
您的基准误差如下-
mysql> select benchmark(1000,(select RegisteredCourse from UserDemo)); ERROR 1242 (21000): Subquery returns more than 1 row
由于子查询返回了多行,因此您需要返回一行。查询如下-
mysql> select RegisteredCourse from UserDemo where UserId=1;
以下是输出-
+------------------+ | RegisteredCourse | +------------------+ | Java | +------------------+ 1 row in set (0.00 sec)