robjwilkins
robjwilkins

Reputation: 5652

Couchbase N1QL value Decode function

Is there an equivalent of the Oracle SQL DECODE function in N1QL?

I.e. a function which allows you to choose to output one or other value, based on a conditional check:

select sum(decode(type = 'car', 1, 0)) carCount from mybucket

thanks

Upvotes: 1

Views: 187

Answers (1)

vsr
vsr

Reputation: 7414

DECODE will be available in next release. In mean time you can use CASE expression

SELECT SUM(CASE WHEN type = 'car' THEN 1 ELSE 0 END) carCount 
FROM mybucket;

Upvotes: 3

Related Questions