在我的Query
中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
我希望它返回由逗号分隔的子查询值,如
id rev content ex
1 1 ....... 1,1,0
但是我一直得到Operand should contain 1 column(s)
,当我想从子查询中返回单个列中的多个列值时,我怎样才能解决这个问题呢?
我得到的是我提到的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
答案 0 :(得分:2)
我相信你想要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