1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] How to group by two different rows in to one matching result

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 7, 2024 às 11:53.

  1. Stack

    Stack Membro Participativo

    I have to write a query to form a Bar chart. In the bar chart x axis should be grouped based on datetime (dateValue) and y axis should have sum of numbers(stringValue). Both these two fields are custom fields in my task_project_field table which has two entries for this values. How to achieve a result where i can group based on datetime and number

    I want to group by month. say May-2024 and sum all the stringValue say (900). Both these values are in two different field_id(field_id 371 and 349) as shown in the table.

    Here is my query:

    SELECT t.id,
    CONCAT(MONTHNAME(tpf.dateValue), '-', year(tpf.dateValue)) as month,
    t.task_name,
    tm.project_id,
    tm.team_id,
    tpf.field_id,
    tpf.dateValue,
    tpf.stringValue
    FROM task as t
    inner join task_membership tm on t.id = tm.task_id
    and tm.deleted_at = 0
    and t.deleted_at = 0
    left join task_project_field as tpf on t.id = tpf.task_id
    and tpf.deleted_at = 0
    WHERE (
    tpf.field_id = 371
    or tpf.field_id = 349
    )
    AND t.id in (2981641);


    Here is my result:

    [​IMG]

    Expected result:

    displayName: "May-2024"
    count: 900

    Continue reading...

Compartilhe esta Página