Create a new column by comparing set of column values

alive

How can I group a set rows by 'product_id' from a table and create a new column by comparing a set of column values within the group ?

For example,

product id   part_id  availability
1            1        true
1            2        false
1            3        true
2            1        true
2            4        true
2            8        true

By comparing the 'availability',I would like to create a 'feasibility' column. If single part is missing it would't be feasible.

product_id  feasibility
1           false
2           true

I used GROUP BY clause to sort'em out by product_id but I can't figure out the second part.

cars10m

There is a very simple solution available, if you are only interested in the two columns shown in your question:

select product_id, min(availability) feasible
from tbl group by product_id

See here for a little demo:. http://rextester.com/GMT80394

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add a new column to dataframe after comparing the values of other columns

Comparing a list to a dataframe column and create new column with numbers

pandas create a new column by comparing two dataframes

Set values in a new column based on a boolean condition

Comparing values in two columns in same table and creating new column

Create a new column based on the values of the column by ID

Create a new dataframe column by comparing two other columns in different dataframes

Efficient way to create new column based on nested if else conditions and comparing values from lists in R

How to create a new column with values from comparing two other columns?

Comparing Column Values With NA

Conditionally Create New Column Based on Row Values

Pyspark: Create new column of the set of values in a groupby

Comparing column values with rowSums

Create new column based on values of another column

Create new column based on values in other columns

Generate a new dataframe with boolean column based on comparing other dataframes values

Create a new column based on values in an existing column

How to create a new column with the derivative of a set of time serie values

comparing values of a column with a variable and make new column

Comparing Cells in Columns and Writing Values to a New Column

Create a new column a fill with values from a set of multiple columns conditional on column names

Create a new column evaluating values in previous column

Create new column with multiple values in Python

Create new column with matched values in R

create new column group by values of other column

Comparing columns and printing comments in a new column based on column values

create new column with incremental values

Create new column with frequency of values

Pandas Dataframe - comparing values of two columns with previous rows to create a new column