MySQL将行转换为列

时间:2018-10-30 16:16:02

标签: mysql sql database

我有一个MySQL查询,它提供以下结果, enter image description here

使用的查询是

SELECT  modi, aid FROM (SELECT 
 GROUP_CONCAT(id) his,
an_id aid, 
GROUP_CONCAT(m_id) modi
FROM 
ah 
GROUP BY an_id, m_id) t1
GROUP BY aid, modi
order by aid;

现在我需要一个MySQL query which will give me a result set where if column帮助has the same value in two rows should create a new column with same帮助and modi`。

例如,图像中的前两行相同aid但不同modi。我需要的结果应该有3列,行应该像这样,

aid           modi                  modi2
27     6,6,6,6,6,6,6,6,6              8

我对SQL非常陌生。预先感谢

1 个答案:

答案 0 :(得分:1)

嗯,一种方法是:

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@RequestMapping(consumes = "application/x.company.v1+json", 
                produces = "application/x.company.v1+json")
public @interface CustomJsonV1RequestMapping {

    @AliasFor(annotation = RequestMapping.class, attribute = "value")
    String[] value() default {};

    @AliasFor(annotation = RequestMapping.class, attribute = "method")
    RequestMethod[] method() default {};

    @AliasFor(annotation = RequestMapping.class, attribute = "params")
    String[] params() default {};

    @AliasFor(annotation = RequestMapping.class, attribute = "headers")
    String[] headers() default {};

    @AliasFor(annotation = RequestMapping.class, attribute = "consumes")
    String[] consumes() default {};

    @AliasFor(annotation = RequestMapping.class, attribute = "produces")
    String[] produces() default {};
}