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.
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.
Comments