![](/img/trans.png)
[英]Picking out and showing only the highest value from one column based on three columns in MySQL
[英]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
我希望它返回以逗号分隔的子查询值
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
我相信你想要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.