Assuming I am executing the following two queries on Druid: I tried to combine both counts in one single query with a sum aggregation like the following: And it works well UNLESS one of the two counts returns 0 rows. In that case I receive a Query returned no data message and I don’t have any final result from the
Tag: case
Filtering null values when casting – using CASE statements
I’ve been trying to query rows with a date field up to a threshold. For reasons beyond my control, all fields are varchar. I’m trying to filter out null values which case an error when cast. My latest attempt: The above code still hits an error trying to cast “” to a date. I thought this would be a common
SQL CASE WHEN: is there a limit ( in number of characters )? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 9 months ago. Improve this question I’m using the case when statement to group locations ( starting & destination lat, long ) into 3 regions. Running 1 query for each region
SQL Substring Case Condition
I’m trying to solve the following question on SQLPAD. Write a query to return the number of actors whose first name starts with ‘A’, ‘B’, ‘C’, or others. The order of your results doesn’t matter. You need to return 2 columns: The first column is the group of actors based on the first letter of their first_name, use the following:
SQL – Using CASE statement with multiple IS NULL, IS NOT NULL
I’m having difficulties writing a case statement with multiple IS NULL, NOT NULL conditions. I have the case statement below, however the third condition (WHEN ID IS NOT NULL AND LABEL IS NULL THEN TITLE) does not seem to be recognised. When Label is null, the statement does not pick up title. Is there a different way to write this
Best way to merge two SQL queries into one query
I have two small SQL queries that I would like to merge to be a single query that I will eventually use in a stored procedure. I have tried a CASE and IF/ELSE but could not get it to work. Below is the code. What I want to achieve is have the first column ‘Count of Open Order Lines’ based
Proper Case in Athena SQL
I’m new to Athena and trying to convert a field ‘Country’ to Proper Case. For example: united states -> United States Is there a way to do this in Athena? Answer Turning a comment into an answer: Athena engine version 2 gives in its RegEx section as example for regexp_replace(string, pattern, function)
Update data based on the previous row in postgresql
For rn (row number) = 1, x and y always stays as 0. Now I need to update the rest of x and y columns based on the above scenario(IF ..ELSE). I am unable to update the next row without updating the previous row. Is there a way to do this in a query Answer You can use a recursive
insert value from join with If/Case from two tables, into a third table
So I have the following issue in creating a sql query. A linked server so am using an open query. (edit update: SQL Server) Two tables as per picture below: I need to insert value into a third table, the value to insert to the third table comes from the two tables above which I join via KEY ID. However,
How use case statement alias in where clause
I’m trying to use a case statement and the results to in an alias, but I need to use the alias in my where clause and this doesn’t seem to be working. How do I use the alias (isPrimary below) in my where clause. See comment where I’m trying to use isPrimary in my where clause, which doesn’t work. How