Let’s say I have two MySQL tables: table1 (templates) Columns: id_template, name, col3, col4, … table2 (aliases) Columns: id_alias, id_template_orig, id_user, alias I want to select a row from the table1 (templates) including all the columns (*). In the same select statement I want to check if current user has saved an alias for the original template name in the
Tag: case
PSQL query to insert the records from one table to another based on condition
I have 2 Postgres tables with the following structure: Lets say I have data in the tmp table as below: Now I want to write a psql INSERT INTO query which will copy the data from public.tmp to public.mo table and also perform below condition When a Host has mix values in STATUS column, for eg if HOST: RhelTest has
Oracle decode equivalent function to Postgres
So, I’m in migrating database from oracle to Postgres, and this is my error: and here’s my code : do you have any clue? From what I’ve read, some say to replace the decode function with COALESCE, but I don’t have any idea how the syntax is. Answer You could use a standard case expression:
Specific hierarchy geography
I have a table geography with three levels I need to display the level3 only for level2 = France, Benelux and for the other countries level2 = level 3 Result Example: Answer
Simple SQL CASE Question – from WHERE to CASE function
Sorry for the noob question, new to SQL here and would appreciate help ๐ I have this SQL query: Will I have the same result if I use this query? (Am I applying the case function correctly here?) If not, can someone help me fix the query below, if possible? *EDIT The original query actually went like this, and I
Mapping two columns into one column in Athena
I have data in the Athena something like this: However, the table owner changed the provider to provider_new. Thus, after 2020-08-01 the provider returns to NULL. Here is my query: How can I map these two columns to one? Thanks in advance. Answer Do you want coalesce()? coalesce() returns the first non-null value of the arguments it is given.
Why is my case statement not returning the value in my โelseโ clause?
I have this section of code and my ELSE is not working. It should return ‘UNKNOWN’ but I am still seeing NULLs in my results. What is going on? case when t2.NEURO_GRP_2 is not NULL …
Find the sum total of two CASE statements – (How to use a CASE expression or Lateral JOIN
I am looking to find the total profit made on an each way horse racing bet I have created a view to show odds and returns for each part of the bet, but I would like to add another column (EachWayProfit) to find the total profit. I have tried to simply SUM the two case statements though receiving a Syntax
How to use CASE WHEN in PostgreSQL without adding values to aggregation and GROUP BY?
I need to take one timestamp if my condition is right and other value, if not. I made such condition: CASE WHEN tr.type = ‘deposit’ THEN tr.timestamp::date ELSE tr.status_last_change_timestamp::date …
How to update row by id using case?
Is it possible to update by id other row values? I try like this But nothig.. UPDATE era SET id = CASE WHEN id = 3 THEN gender = ‘Female’–or maybe it is possible to call insert command here? …