[英]Getting 1 column out of Three columns from Subquery
SELECT a.id, a.rev, a.content,
(
SELECT
EXISTS(SELECT id FROM `docs` WHERE id = 1),
EXISTS(SELECT id FROM `docs` WHERE id = 2),
EXISTS(SELECT id FROM `docs` WHERE id = 3)
) AS ex
FROM `docs` a
I want it to return the Subquery values separated by commas like that 我希望它返回以逗号分隔的子查询值
id rev content ex
1 1 ....... 1,1,0
But i keep getting Operand should contain 1 column(s)
, How can I deal with this problem overall when I want to return multiple column values in a single column from a Subquery? 但是我一直在获取
Operand should contain 1 column(s)
,当我想从子查询的单个列中返回多个列值时,如何整体上解决此问题?
What I get is the error
I mentioned but what i want to get is 我得到的是我提到的
error
但我想得到的是
id rev content ex
1 1 The earth is flat 1,1,0
1 2 The earth is flat and rests on a bull's horn 1,1,0
1 3 The earth is like a ball. 1,1,0
2 1 One hundred angels can dance on the head of a pin 1,1,0
I believe you want CONCAT
: 我相信你想要
CONCAT
:
SELECT a.id, a.rev, a.content,
CONCAT(CAST(EXISTS(SELECT id FROM `docs` WHERE id = 1) as char(1)),',',
CAST(EXISTS(SELECT id FROM `docs` WHERE id = 2) as char(1)),',',
CAST(EXISTS(SELECT id FROM `docs` WHERE id = 3) as char(1))
) AS ex
FROM `docs` a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.