There are lots of way to achieve this, but I'll use inner join
because this will work in most DBMS.
SELECT a.id,a.classification,a.key,
CASE b.value WHEN 'valid' THEN 'valid' ELSE ' ' END as value,
a.date_time
from table_A a
INNER JOIN table_A b ON a.classification = b.classification
AND a.date_time = b.date_time AND b.key = 'Status'
WHERE a.keys <> 'Status'
but I think you have to make sure there is no duplicate classification
with same date_time
with this query.
Aside from the problem itself, OP should normalize your data, this "problem" will not even exist if the data have been proper normalize.
FOR EXAMPLE:
id |
class |
key |
value |
date |
valid |
1 |
NUM_A |
ODD |
7 |
01-11-2021 01:00 |
valid |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…