I have this query:
SELECT time as "time", tag as "tag", value as "value" FROM metrics WHERE tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_32A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_63A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_80A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_125A' GROUP BY 2, 1, 3 ORDER BY time desc LIMIT 4
Which results in this:
Instead of returning all the 4 rows, I’d like to return the column which has a value “1”. How can I achieve this?
Advertisement
Answer
If you just want it to show the column with value = 1, you already have the answer. With mi answer you select all the columns with values different to 0.
SELECT time as "time", tag as "tag", value as "value" FROM metrics WHERE value != 0 AND ( tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_32A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_63A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_80A' OR tag = 'KEB1.DB_IN.01.STATUS_CMD.A_LIM_125A' ) GROUP BY 2, 1, 3 ORDER BY time desc LIMIT 4