[英]ERROR 1241 (21000): Operand should contain 1 column(s) - School project
SELECT naam, adres, postcode, plaats, telefoon
FROM klanten
WHERE plaats IN (SELECT * FROM(
(SELECT plaats, COUNT(plaats) AS W
FROM klanten
GROUP BY plaats
ORDER BY W DESC LIMIT 1) AS T));
So, where did I goof? 所以,我在哪里傻瓜? Where is my syntax mistake or am I derping.
我的语法错误在哪里?
My goal is to print name (naam), adres (address), place (plaats), telephone (telefoon) from the city where the most customers (klanten) live.And before you ask, I'm doing this for a school project and we have to use an older version of MySQL that doesn't allow LIMIT 1 in subqueries. 我的目标是从居住人数最多的城市打印姓名(naam),地址(address),地点(plaats),电话(telefoon)。在您提出要求之前,我正在为一个学校项目做这件事并且我们必须使用不允许在子查询中使用LIMIT 1的旧版MySQL。 That's why the
Select * FROM
is there with the subquery. 这就是为什么
Select * FROM
与子查询一起存在的原因。
The query you are trying to write looks like this: 您尝试编写的查询如下所示:
SELECT naam, adres, postcode, plaats, telefoon
FROM klanten
WHERE plaats IN (SELECT plaats
FROM klanten
GROUP BY plaats
ORDER BY COUNT(*) DESC
LIMIT 1
);
The syntax error is because the IN
subquery is returning two columns -- that is pretty obvious from the message. 语法错误是因为
IN
子查询返回两列-从消息中很明显。 The subquery in the subquery is not necessary; 子查询中的子查询不是必需的。 you can
ORDER BY
an aggregation expression. 您可以对聚合表达式进行
ORDER BY
。
Also, IN
is a bit misleading. 另外,
IN
有点误导。 You can just use =
. 您可以只使用
=
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.