I want to make a select statement to have an overview of the status of each product. The status of a product can either be OK or NOT_OK and a product can be tested multiple times. I want to have the "worst" status for each product: I want to have NOT_OK if the product has already been tested at least once as NOT_OK and else OK.
Here is a little data sample:
PRODUCT | STATUS | DATA_PRODUCT_SPECIFIC_TO_KEEP
--------+-----------+--------------------------------
A | NOT_OK | AAA
A | OK | AAA
B | OK | BBB
B | OK | BBB
B | OK | BBB
C | NOT_OK | CCC
Here is the result I expect to have:
PRODUCT | STATUS | DATA_PRODUCT_SPECIFIC_TO_KEEP
--------+-----------+--------------------------------
A | NOT_OK | AAA
B | OK | BBB
C | NOT_OK | CCC
I tried to use the query below:
SELECT PRODUCT, count(STATUS="NOT_OK"), DATA_PRODUCT_SPECIFIC_TO_KEEP
FROM TABLE
GROUP BY PRODUCT
but this is rejected by the error
missing right parenthesis
Do you have any idea?