查询以对内部联接行进行分组

时间:2021-09-17 22:34:45

I have 2 tables: Projects and custom_values which are linked by the project id. I did this inner join query

我有2个表:项目和custom_values,它们由项目ID链接。我做了这个内连接查询

SELECT custom_values.customized_id ,custom_values.custom_field_id,
custom_values.value FROM projects INNER JOIN custom_values ON    
projects.id=custom_values.customized_id order by custom_values.customized_id asc

You will find the responce of this query in the file joined. 查询以对内部联接行进行分组

您将在已加入的文件中找到此查询的响应。

I want to know if there is a way to group those rows by customized_id field. By the way I tried Group by but it doesn't work

我想知道是否有一种方法可以通过customized_id字段对这些行进行分组。顺便说一句,我尝试过Group by但它不起作用

1 个解决方案

#1


2  

If you want group you need a aggregation function eg (max, min group_concat) and group by , if you want all the values related to a customized_id on a row you could use group_concat eg:

如果你想要组,你需要一个聚合函数,例如(max,min group_concat)和group by,如果你想在一行上有一个与customized_id相关的所有值你可以使用group_concat,例如:

SELECT custom_values.customized_id 
  ,group_concat(custom_values.value )
FROM projects 
INNER JOIN custom_values ON projects.id=custom_values.customized_id 
GROUP BY custom_values.customized_id 
order by custom_values.customized_id asc

#1


2  

If you want group you need a aggregation function eg (max, min group_concat) and group by , if you want all the values related to a customized_id on a row you could use group_concat eg:

如果你想要组,你需要一个聚合函数,例如(max,min group_concat)和group by,如果你想在一行上有一个与customized_id相关的所有值你可以使用group_concat,例如:

SELECT custom_values.customized_id 
  ,group_concat(custom_values.value )
FROM projects 
INNER JOIN custom_values ON projects.id=custom_values.customized_id 
GROUP BY custom_values.customized_id 
order by custom_values.customized_id asc