简体   繁体   English

从子查询中检索多个列

[英]Muliple column retrieval from Subquery

I have a table tasks and another table master_employee 我有一个表任务和另一个表master_employee

i am trying to list some task details alongside with a String that is going to be parsed as a json object 我正在尝试列出一些任务详细信息以及将被解析为json对象的String

   SELECT task_name,assignees,priority,
   DATE_FORMAT(due_date, "%M %d %Y") as due_date ,

  (select GROUP_CONCAT(CONCAT('{ id:"',emp_id, '",name:"',first_name ,'"}')) as list 
   from master_employee where emp_id in(2925,2913))  as list 
   FROM tasks
   where task_id=4189

The String that i was referring to is the is the column alias 'list' . 我所指的字符串是列别名'list'。 so the problem is ,as we know subqueries does not return multiple values , the query returns the concatenated values of only one emp_id . 所以问题是,正如我们所知,子查询不返回多个值,查询仅返回一个emp_id的串联值。 i want ,for example in this case concatenated values of emp_id's 2925 and 2913 我想要,例如在这种情况下emp_id的2925和2913的串联值

Probably you are using GROUP_CONCAT function without the GROUP BY clause. 可能您正在使用不带GROUP BY子句的GROUP_CONCAT函数。 if you don't have suitable field for group then just use group by with anything for example 1 or '1' 如果您没有适合分组的字段,则只需使用分组依据,例如1或'1'

SELECT task_name,assignees,priority,
DATE_FORMAT(due_date, "%M %d %Y") as due_date , (
  select GROUP_CONCAT(CONCAT('{ id:"',emp_id, '",name:"',first_name 
  ,'"}')) as list 
  from master_employee where emp_id in(2925,2913)
  GROUP BY '1'
) as list 
FROM tasks
where task_id=4189

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM