Reputation: 79
I have a condition that I need to query Couchbase database field with two different where clauses in the same query. for example: for 'sales' field in a database entity, I want to have one query to get the sales in a single hour and whole day
output example:
`{`
`hourly_sales = 500`
`total_day_sales = 5000
`}`
I know that I can use 2 different queries, but requirement is to use one query for both
Upvotes: 2
Views: 23
Reputation: 700
You can achieve that using case when statement. For example -
SELECT SUM(CASE WHEN `TIME` BETWEEN "13:00:00" AND "14:00:00" THEN `SALES`) AS HOURLY_SALES,
SUM(CASE WHEN `TIME` BETWEEN "00:00:00" AND "23:59:59" THEN `SALES`) AS TOTAL_DAY_SALES
FROM `BUCKET_NAME`
Make use of the time format according to your need.
Upvotes: 1