1

I have a data set whose original values are integers.

The SQL is straightforward:

SELECT last("DischargingBattery") FROM battery

I would like to convert the none zero numbers into "BUSY" string and zero number into "IDLE". The SQL would like similar to following:


SELECT last("DischargingBattery") ,

    CASE
        WHEN last("DischargingBattery") = 0 THEN 'IDLE'
        ELSE 'BUSY'
    END AS DischargingBatteryStatus

FROM battery

However, I didn't find any reference in the doc yet.

Any workaround?

Munin
  • 1,576
  • 2
  • 19

1 Answers1

1

I can not find any reference to case in any CnosDB docs either, so I'm drawn to the conclusion that it isn't (currently?) supported.

Also there does not seem to be "if" of "iif" with the select clause either.

So, in your case all I can suggest as an alternative is (but I dislike it):

SELECT
      0      as DischargingBattery
    , 'IDLE' AS DischargingBatteryStatus
FROM battery
WHERE last("DischargingBattery") = 0

UNION ALL

SELECT
      last("DischargingBattery")
    , 'BUSY' DischargingBatteryStatus
FROM battery
WHERE last("DischargingBattery") <> 0

NB: I am not familiar with the function last

Paul Maxwell
  • 33,002
  • 3
  • 32
  • 51