Hope some can help ? I have a 3rd party software were i can do custom sql querys but not able to change any of the database. Struggling to get the result i would like. Do I use GROUP BY or CTE to get the result i need? This give me the result below . I have removed Where c=1
Tag: case
Can I use a derived column in SQL Server for performing a CASE function?
I have a ‘main’ table, C1, which has a record identifier, which in turn may be linked to either an account or a customer ID. The relationship / linkage is stored on two separate tables, one with record ID – Account level relationship, and the other with record ID – Customer level relat…
Apply limit to CASE statement
I am trying to collect counts of different columns for players (you don’t need to know the ins and outs of all the columns). We have a player_1 and player_2 column so I have made it distinct to get total counts, as you can see below: I want to also get the frequency of goals for last 32 games for
Hive Query to insert a value conditionally
I have a Table1 containing some blacklisted names. Now suppose I receive a record “def”. The hive query should check if “def” is present in Table1 or not. If not the name_status should be set to blacklisted otherwise null. The name “def” will be inserted in both cases. The …
SQL Case Order By specific order and Direction
I have a table that I need sorted on fields By @SortBy and @SortDirection, for ID,PriorityID,stateType (column type is int) result is OK, but for Title (nvarchar) Query Result is: Conversion failed when converting the nvarchar value ‘Title Column value’ to data type int. Query: Answer The types ar…
case statement is returning a 0 instead of empty string
I have the following case statement; I would like it to return But the output I am getting is; I dont want the zeros, I would like the empty string. Answer You want to return a string, so you need to cast the else:
Hive query conditional statement in same select query
Is there a way to get in one single hive query to do a if-else kind of setup. In the my data below I want to ensure that if Model is empty or having ‘-‘ I populate the Final column with Device else it should be populated with Model Can someone please help here. Answer Read about CASE operator synt…
Set prefix in SQL CASE expression
I have problem setting a prefix in a case statement. Data set: When I run this query my result is this: Desired result is this: As one can see, the first zero is not shown in the result. How can I achieve this? Answer CASE expression would always return one type so, you need to do conversion:
GROUP BY with nested case expression – is there better way?
SQL server 2012 I am taking fees received and multiplying them by different factors based on how long the Client has been a Client. The group by clause is fairly straight forward. However, my select gets awkward when I want to use this criteria in different ways: I suppose I should mention this is a simplifie…
ORA-00937 not a single-group group function when using CASE Condition
I’ve been searching for a few hours now, on how to resolve an ORA-00937: not a single-group group function and none of them seem to explain why I am getting the error. My understanding is, when applying an aggregate function in the select statement on one or more columns, than you should include the col…