I have a simple case statement as follows: This code is designed to return ‘A_VALUE_ANYWAY’ because there is no output from the SQL. However, it does not return anything at all. Essentially, what I would like is a value being forced to return from the case statement instead of just no rows. Am I a…
SQL how to select distinct several columns
lets say there are several columns (c1, c2, c3, c4) It’s okay for each column to be appeared several times, but I want to select all the columns with several columns distinct. I want SELECT c1, DISTINCT(c2, c3), c4 something like this but it doesnt work, and GROUP BY doesnt work as well. somebody help m…
Get records greater than 1 for same status
I have table logs Table 2 status_master So, now I’m trying to get the retry count for each scenario. Expected result Answer Sounds like an aggregation of an aggregation to me. Try: Results status count 2 1 19 1 My results were different than your expected results. Did you mean for status = 1 to be statu…
Latest value of compared date range? (SQL/Snowflake)
I have values in Table-A like: And values in Table-B like: And I want to join the two tables such that I see the most recent cumulative sum of values in Table-B as-of the Date in Table-A for a given Patient. How would I join these two tables by date to accomplish this? Answer First step seems like a basic
Unable to find error in the query – Snowflake
Error: SQL compilation error: error line 105 at position 8 invalid identifier ‘INTENT’. There are two CTE’s, and then the select statement. First CTE works fine if run separately, the error is in the second CTE. I am not sure what is causing the syntax error. Thanks in advance. Answer Snowfl…
COUNT with CASE WHEN is showing the same result when using division
I have the following query which returns the sold products: I want to calculate the percentage of the sold products comparing to all products for product_category =7 : I get the result as 100, while I execute each query separately they don’t have the same result. Answer count() counts both 0 and 1s, it …
SQL Oracle fusion lines with same id
Here is a simplification of my problem: I would like to have a result like this (keeping those 2 selects): Not sure how to fusion those 2 lines One ugly solution is: Answer For me it looks like a join with nvl for me: I’m not sure about your data, so probably it should be just left/right join or even
Create table in snowflake – Syntax
I am trying to create a table and insert rows into it. But it keeps giving me this syntax error. ERROR : SQL compilation error: syntax error line 3 at position 1 unexpected ‘EventName’. syntax Any help would be appreciated. Answer You need to type those columns, and you are missing a comma after t…
SELECT a query after another SELECT using Dates
i have a table that uses TIMESTAMPS an needs to be filtered by month, the query is: now, from the results of this query i need to use another query that groups the dates by day and makes a sum of a field, in the same table: How can i join this two querys so the two separated queries can
Oracle SQL: Dividing Counts into unique and non unique columns
I have a table that looks like this: I want to aggregate by FileID and split the File Info column into 2 separate count columns. I want 1 column to have the count of the Unique File Info and the other to be a count of non-Unique file info. The result would ideally look like this: where the non-unique count