Debasish Halder
Debasish Halder

Reputation: 173

how can I can running status from my table?

I have a below table which has multiple rows with same executionid and different status. How can I get the row which status is running, rows will be exclude if executionid associated with both running and completed status?

Below image is the sample data :

enter image description here

Expected result should be: enter image description here

Upvotes: 0

Views: 94

Answers (2)

trillion
trillion

Reputation: 1401

  • Using String_AGG() to get all the status per execution id into one list
  • Joining that list to the original data and then filtering out the results using NOT LIKE operator, if there are cases that are completed and running then they are not selected
with all_status as (
Select

execution_id,
STRING_AGG (status,', ') as all_status_per_id
from [table]
)

Select 
data.*,
all_status.all_status_per_id
from [table] as data
left join all_status 
on data.execution_id = all_status.execution_id
where (all_status.all_status_per_id LIKE '%running%' AND all_status.all_status_per_id NOT LIKE '%completed%')
AND status = 'running'

Upvotes: 1

Belayer
Belayer

Reputation: 14861

Simple select:

select * 
  from your_table
 where status = 'running';

This is about as basic SQL statement that tou can get. I suggest you get a SQL text, and try a few tutorials.

Upvotes: 0

Related Questions