Calculating Main Current Task column by concatenating 2 task names based on multiple conditions

Copper Contributor

Calculating Main Current Task column by concatenating 2 task names based on multiple conditions

Hello, I am trying to solve the problem if someone can help that would be appreciated. I am beginning my journey with SQL.

Desired Output - Main Current Task Column

Task ID column is in ASCENDING order, and each language as a group has multiple Parent tasks.

1st Condition

I am trying to calculate Main Current Task Column in such a way where ever Tsk Status is Delivered and Project_Deliverable_Not_Deliverable is 'Deliverable' between one Parent and other parent (i.e., Column - Parent_Find) within a same language group it concatenates the Task of Parent + Task from the row which as Delivered status from Tsk Status column (i.e., Task 3) and gives Main Current Task as Task 1 + Task 3

Likewise Task 4 + Task 9 for second Parent within same English language.

2nd if CONDITION understanding

Can be any langauge, but For example lets say for Czech, as a language group Tsk Status is delivered for Task B but Project_Deliverable_Not_Deliverable is 'Non-Deliverable' hence no concatenation with Parent task as earlier just Task B.

and Task D as a output within same Czech group as new parent is present, (order by ASC Tsk Id column) because Tsk Status is delivered, Project_Deliverable_Not_Deliverable is deliverable and Parent at a same time, hence only picking Task D.

I was thinking to develop a logic saying where Parent Find = Parent and Tsk Id < Tsk Id of 2nd Parent within same language group and write if else statements to pick the relative task from  Task Type column and then concatenate with Task of the parent.

Issue is there can be multiple parent within a language group order by Tsk Id ASC

Any help with the logic is helpful. Thanks.

2 Replies

Re: Calculating Main Current Task column by concatenating 2 task names based on multiple conditions

Based on the provided description and sample data, it seems that you are looking for a logic to calculate the "Main Current Task" column based on certain conditions. Here's a possible approach to achieve that:

Create a temporary table or view with the necessary columns: Job ID, Language, Task Type, Parent_Find, Tsk Id, Tsk Status, and Project_Deliverable_Not_Deliverable.

Use the following SQL query to calculate the "Main Current Task" column:

SELECT
t1.`Job ID`,
t1.`Language`,
t1.`Parent_Find`,
t1.`Tsk Id`,
t1.`Tsk Status`,
CASE
WHEN t1.`Tsk Status` = 'Delivered' AND t1.`Project_Deliverable_Not_Deliverable` = 'Deliverable' THEN
(SELECT CONCAT(' + ', t2.`Task Type`)
FROM your_table_name t2
WHERE t2.`Language` = t1.`Language`
AND t2.`Parent_Find` = t1.`Parent_Find`
AND t2.`Tsk Status` = 'Delivered'
AND t2.`Project_Deliverable_Not_Deliverable` = 'Deliverable'
AND t2.`Tsk Id` > t1.`Tsk Id`
ORDER BY t2.`Tsk Id` ASC
LIMIT 1)
ELSE ''
END